From 0eb24d8ab4c2f1cbdf412c3d94645f8da7655dac Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Wed, 24 Jun 2020 13:48:54 -0700 Subject: [PATCH 1/2] Add `IP_PORTRANGE*` constants to the socket module `IP_PORTRANGE*` can be used for getting/setting port ranges on a per socket basis, as opposed to a system wide basis, in conjunction with calls like `socket.getsockopt` and `socket.setsockopt`. This functionality is available on \*BSD and Linux. Signed-off-by: Enji Cooper --- Doc/library/socket.rst | 12 ++++++++++++ Modules/socketmodule.c | 14 ++++++++++++++ 2 files changed, 26 insertions(+) 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/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); From 908a86ee22074cfa0eb7c34d760e861e62e09b1c Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 19 Oct 2025 07:47:55 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2025-10-19-07-47-49.gh-issue-85280.MKUX1l.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-10-19-07-47-49.gh-issue-85280.MKUX1l.rst 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.