Skip to content

Commit e2c64c5

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 26d9b25 commit e2c64c5

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎Doc/library/socket.rst‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ The AF_* and SOCK_* constants are now :class:`AddressFamily` and
418418
MSG_*
419419
SOL_*
420420
SCM_*
421+
IP_PORTRANGE*
421422
IPPROTO_*
422423
IPPORT_*
423424
INADDR_*
@@ -833,6 +834,17 @@ The AF_* and SOCK_* constants are now :class:`AddressFamily` and
833834

834835
.. availability:: not WASI.
835836

837+
.. data:: IP_PORTRANGE
838+
IP_PORTRANGE_DEFAULT
839+
IP_PORTRANGE_HIGH
840+
IP_PORTRANGE_LOW
841+
842+
These constants are available for manipulating port ranges on a socket-level
843+
as opposed to system-level.
844+
845+
.. availability:: BSD, Linux.
846+
.. versionchanged:: 3.15
847+
836848
Functions
837849
^^^^^^^^^
838850

‎Modules/socketmodule.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8815,6 +8815,14 @@ socket_exec(PyObject *m)
88158815
ADD_INT_MACRO(m, SYSPROTO_CONTROL);
88168816
#endif
88178817

8818+
/* Unix-specific macros for setting IP port ranges. */
8819+
#ifdef IP_PORTRANGE
8820+
PyModule_AddIntMacro(m, IP_PORTRANGE);
8821+
PyModule_AddIntMacro(m, IP_PORTRANGE_DEFAULT);
8822+
PyModule_AddIntMacro(m, IP_PORTRANGE_HIGH);
8823+
PyModule_AddIntMacro(m, IP_PORTRANGE_LOW);
8824+
#endif
8825+
88188826
/* Some port configuration */
88198827
#ifdef IPPORT_RESERVED
88208828
ADD_INT_MACRO(m, IPPORT_RESERVED);

0 commit comments

Comments
 (0)