From e2c64c592a93cf11d92d89067dac2c8f13a00334 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 | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst index 836aa91bb0885b1..b4461a660ee46ad 100644 --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -418,6 +418,7 @@ The AF_* and SOCK_* constants are now :class:`AddressFamily` and MSG_* SOL_* SCM_* + IP_PORTRANGE* IPPROTO_* IPPORT_* INADDR_* @@ -833,6 +834,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 70d3738b176cda2..74980c4854db128 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -8815,6 +8815,14 @@ 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); + PyModule_AddIntMacro(m, IP_PORTRANGE_DEFAULT); + PyModule_AddIntMacro(m, IP_PORTRANGE_HIGH); + PyModule_AddIntMacro(m, IP_PORTRANGE_LOW); +#endif + /* Some port configuration */ #ifdef IPPORT_RESERVED ADD_INT_MACRO(m, IPPORT_RESERVED); From 79376ef0528c8740075f884f505f0799aa947c5b 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 000000000000000..f1cc5119756e4f3 --- /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.