Skip to content

Commit 03910d1

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 cfd6cf7 commit 03910d1

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
@@ -8845,6 +8845,14 @@ socket_exec(PyObject *m)
88458845
ADD_INT_MACRO(m, SYSPROTO_CONTROL);
88468846
#endif
88478847

8848+
/* Unix-specific macros for setting IP port ranges. */
8849+
#ifdef IP_PORTRANGE
8850+
PyModule_AddIntMacro(m, IP_PORTRANGE);
8851+
PyModule_AddIntMacro(m, IP_PORTRANGE_DEFAULT);
8852+
PyModule_AddIntMacro(m, IP_PORTRANGE_HIGH);
8853+
PyModule_AddIntMacro(m, IP_PORTRANGE_LOW);
8854+
#endif
8855+
88488856
/* Some port configuration */
88498857
#ifdef IPPORT_RESERVED
88508858
ADD_INT_MACRO(m, IPPORT_RESERVED);

0 commit comments

Comments
 (0)