Skip to content

Commit d0305a4

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 87f649a commit d0305a4

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
@@ -348,6 +348,7 @@ Constants
348348
MSG_*
349349
SOL_*
350350
SCM_*
351+
IP_PORTRANGE*
351352
IPPROTO_*
352353
IPPORT_*
353354
INADDR_*
@@ -544,6 +545,17 @@ Constants
544545

545546
.. availability:: Linux >= 4.7.
546547

548+
.. data:: IP_PORTRANGE
549+
IP_PORTRANGE_DEFAULT
550+
IP_PORTRANGE_HIGH
551+
IP_PORTRANGE_LOW
552+
553+
These constants are available for manipulating port ranges on a socket-level
554+
as opposed to system-level.
555+
556+
.. availability:: BSD, Linux
557+
.. versionchanged:: 3.9
558+
547559
Functions
548560
^^^^^^^^^
549561

Modules/socketmodule.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7952,6 +7952,20 @@ PyInit__socket(void)
79527952
PyModule_AddIntMacro(m, SYSPROTO_CONTROL);
79537953
#endif
79547954

7955+
/* Unix-specific macros for setting */
7956+
#ifdef IP_PORTRANGE
7957+
PyModule_AddIntMacro(m, IP_PORTRANGE);
7958+
#endif
7959+
#ifdef IP_PORTRANGE_DEFAULT
7960+
PyModule_AddIntMacro(m, IP_PORTRANGE_DEFAULT);
7961+
#endif
7962+
#ifdef IP_PORTRANGE_HIGH
7963+
PyModule_AddIntMacro(m, IP_PORTRANGE_HIGH);
7964+
#endif
7965+
#ifdef IP_PORTRANGE_LOW
7966+
PyModule_AddIntMacro(m, IP_PORTRANGE_LOW);
7967+
#endif
7968+
79557969
/* Some port configuration */
79567970
#ifdef IPPORT_RESERVED
79577971
PyModule_AddIntMacro(m, IPPORT_RESERVED);

0 commit comments

Comments
 (0)