diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst index 89bca9b5b20df7..b5edc933cf8c47 100644 --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -416,6 +416,7 @@ The AF_* and SOCK_* constants are now :class:`AddressFamily` and MSG_* SOL_* SCM_* + IP_PORTRANGE* IPPROTO_* IPPORT_* INADDR_* @@ -827,6 +828,17 @@ The AF_* and SOCK_* constants are now :class:`AddressFamily` and .. availability:: not WASI. +.. data:: IP_PORTRANGE + IP_PORTRANGE_DEFAULT + IP_PORTRANGE_HIGH + IP_PORTRANGE_LOW + + These constants are available for manipulating port ranges on a socket-level + as opposed to system-level. + + .. availability:: BSD, Linux. + .. versionchanged:: 3.15 + Functions ^^^^^^^^^ diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-10-19-07-47-49.gh-issue-85280.MKUX1l.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-19-07-47-49.gh-issue-85280.MKUX1l.rst new file mode 100644 index 00000000000000..f1cc5119756e4f --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-19-07-47-49.gh-issue-85280.MKUX1l.rst @@ -0,0 +1 @@ +Add the ``IP_PORTRANGE*`` constants to :mod:`socket` on supporting systems. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index dd4b6892977484..0ea5a2e27343c5 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -8728,6 +8728,20 @@ socket_exec(PyObject *m) ADD_INT_MACRO(m, SYSPROTO_CONTROL); #endif + /* Unix-specific macros for setting IP port ranges. */ +#ifdef IP_PORTRANGE + PyModule_AddIntMacro(m, IP_PORTRANGE); +#endif +#ifdef IP_PORTRANGE_DEFAULT + PyModule_AddIntMacro(m, IP_PORTRANGE_DEFAULT); +#endif +#ifdef IP_PORTRANGE_HIGH + PyModule_AddIntMacro(m, IP_PORTRANGE_HIGH); +#endif +#ifdef IP_PORTRANGE_LOW + PyModule_AddIntMacro(m, IP_PORTRANGE_LOW); +#endif + /* Some port configuration */ #ifdef IPPORT_RESERVED ADD_INT_MACRO(m, IPPORT_RESERVED);