Skip to content

Commit

Permalink
pythongh-104061: Add socket.SO_BINDTOIFINDEX constant (pythonGH-104062)
Browse files Browse the repository at this point in the history
Add socket.SO_BINDTOIFINDEX constant

This socket option avoids a race condition between SO_BINDTODEVICE and network interface renaming.
  • Loading branch information
viccie30 authored and diegorusso committed Apr 17, 2024
1 parent ba4df53 commit e31d445
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Doc/library/socket.rst
Expand Up @@ -445,6 +445,11 @@ Constants
Added ``IP_PKTINFO``, ``IP_UNBLOCK_SOURCE``, ``IP_BLOCK_SOURCE``,
``IP_ADD_SOURCE_MEMBERSHIP``, ``IP_DROP_SOURCE_MEMBERSHIP``.

.. versionchanged:: 3.13
Added ``SO_BINDTOIFINDEX``. On Linux this constant can be used in the
same way that ``SO_BINDTODEVICE`` is used, but with the index of a
network interface instead of its name.

.. data:: AF_CAN
PF_CAN
SOL_CAN_*
Expand Down
@@ -0,0 +1 @@
Add :data:`socket.SO_BINDTOIFINDEX` constant.
3 changes: 3 additions & 0 deletions Modules/socketmodule.c
Expand Up @@ -7927,6 +7927,9 @@ socket_exec(PyObject *m)
#ifdef SO_BINDTODEVICE
ADD_INT_MACRO(m, SO_BINDTODEVICE);
#endif
#ifdef SO_BINDTOIFINDEX
ADD_INT_MACRO(m, SO_BINDTOIFINDEX);
#endif
#ifdef SO_PRIORITY
ADD_INT_MACRO(m, SO_PRIORITY);
#endif
Expand Down

0 comments on commit e31d445

Please sign in to comment.