Skip to content

Commit 04831c8

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 <yaneurabeya@gmail.com>
1 parent f41e9c7 commit 04831c8

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎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
@@ -8673,6 +8673,20 @@ socket_exec(PyObject *m)
86738673
ADD_INT_MACRO(m, SYSPROTO_CONTROL);
86748674
#endif
86758675

8676+
/* Unix-specific macros for setting */
8677+
#ifdef IP_PORTRANGE
8678+
PyModule_AddIntMacro(m, IP_PORTRANGE);
8679+
#endif
8680+
#ifdef IP_PORTRANGE_DEFAULT
8681+
PyModule_AddIntMacro(m, IP_PORTRANGE_DEFAULT);
8682+
#endif
8683+
#ifdef IP_PORTRANGE_HIGH
8684+
PyModule_AddIntMacro(m, IP_PORTRANGE_HIGH);
8685+
#endif
8686+
#ifdef IP_PORTRANGE_LOW
8687+
PyModule_AddIntMacro(m, IP_PORTRANGE_LOW);
8688+
#endif
8689+
86768690
/* Some port configuration */
86778691
#ifdef IPPORT_RESERVED
86788692
ADD_INT_MACRO(m, IPPORT_RESERVED);

0 commit comments

Comments
 (0)