From 03910d19a56137b603530eb80de65f9a78a8c7ff 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 054ccc556740c2..5b417be081710c 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 5fec77a2b82bf7..0b78f03e653934 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -8845,6 +8845,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 fae36bd1561212ac2f50d6c60037db175c526ef6 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 5 Oct 2026 18:24:26 +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 --- .../next/C_API/2026-10-05-18-24-15.gh-issue-85280.KaJQLQ.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/C_API/2026-10-05-18-24-15.gh-issue-85280.KaJQLQ.rst diff --git a/Misc/NEWS.d/next/C_API/2026-10-05-18-24-15.gh-issue-85280.KaJQLQ.rst b/Misc/NEWS.d/next/C_API/2026-10-05-18-24-15.gh-issue-85280.KaJQLQ.rst new file mode 100644 index 00000000000000..f1cc5119756e4f --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2026-10-05-18-24-15.gh-issue-85280.KaJQLQ.rst @@ -0,0 +1 @@ +Add the ``IP_PORTRANGE*`` constants to :mod:`socket` on supporting systems.