Skip to content

Commit 0eb24d8

Browse files
committed
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 <[email protected]>
1 parent c6d4c79 commit 0eb24d8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Doc/library/socket.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ The AF_* and SOCK_* constants are now :class:`AddressFamily` and
416416
MSG_*
417417
SOL_*
418418
SCM_*
419+
IP_PORTRANGE*
419420
IPPROTO_*
420421
IPPORT_*
421422
INADDR_*
@@ -827,6 +828,17 @@ The AF_* and SOCK_* constants are now :class:`AddressFamily` and
827828

828829
.. availability:: not WASI.
829830

831+
.. data:: IP_PORTRANGE
832+
IP_PORTRANGE_DEFAULT
833+
IP_PORTRANGE_HIGH
834+
IP_PORTRANGE_LOW
835+
836+
These constants are available for manipulating port ranges on a socket-level
837+
as opposed to system-level.
838+
839+
.. availability:: BSD, Linux.
840+
.. versionchanged:: 3.15
841+
830842
Functions
831843
^^^^^^^^^
832844

Modules/socketmodule.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8728,6 +8728,20 @@ socket_exec(PyObject *m)
87288728
ADD_INT_MACRO(m, SYSPROTO_CONTROL);
87298729
#endif
87308730

8731+
/* Unix-specific macros for setting IP port ranges. */
8732+
#ifdef IP_PORTRANGE
8733+
PyModule_AddIntMacro(m, IP_PORTRANGE);
8734+
#endif
8735+
#ifdef IP_PORTRANGE_DEFAULT
8736+
PyModule_AddIntMacro(m, IP_PORTRANGE_DEFAULT);
8737+
#endif
8738+
#ifdef IP_PORTRANGE_HIGH
8739+
PyModule_AddIntMacro(m, IP_PORTRANGE_HIGH);
8740+
#endif
8741+
#ifdef IP_PORTRANGE_LOW
8742+
PyModule_AddIntMacro(m, IP_PORTRANGE_LOW);
8743+
#endif
8744+
87318745
/* Some port configuration */
87328746
#ifdef IPPORT_RESERVED
87338747
ADD_INT_MACRO(m, IPPORT_RESERVED);

0 commit comments

Comments
 (0)