From 59ff354a28ddc968717823e4ad2317db2c4c6386 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Mon, 31 Aug 2026 08:45:25 -0400 Subject: [PATCH 1/6] Gate socket.if_{nametoindex, indextoname} on respective OS capability --- Modules/clinic/socketmodule.c.h | 8 ++++---- Modules/socketmodule.c | 12 +++++++++--- configure.ac | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Modules/clinic/socketmodule.c.h b/Modules/clinic/socketmodule.c.h index f89b91b9b997532..894c5f7c641457e 100644 --- a/Modules/clinic/socketmodule.c.h +++ b/Modules/clinic/socketmodule.c.h @@ -2181,7 +2181,7 @@ _socket_if_nameindex(PyObject *module, PyObject *Py_UNUSED(ignored)) #endif /* (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)) */ -#if (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)) +#if (defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS)) PyDoc_STRVAR(_socket_if_nametoindex__doc__, "if_nametoindex($module, oname, /)\n" @@ -2213,9 +2213,9 @@ _socket_if_nametoindex(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)) */ +#endif /* (defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS)) */ -#if (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)) +#if (defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)) PyDoc_STRVAR(_socket_if_indextoname__doc__, "if_indextoname($module, if_index, /)\n" @@ -2244,7 +2244,7 @@ _socket_if_indextoname(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)) */ +#endif /* (defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)) */ #if defined(CMSG_LEN) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 70d3738b176cda2..82899572f80255a 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -631,14 +631,14 @@ _PyLong_##NAME##_Converter(PyObject *obj, void *ptr) \ return 1; \ } -#if defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS) +#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS) # ifdef MS_WINDOWS UNSIGNED_INT_CONVERTER(NetIfindex, NET_IFINDEX) # else # define _PyLong_NetIfindex_Converter _PyLong_UnsignedInt_Converter # define NET_IFINDEX unsigned int # endif -#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS) +#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS) /*[python input] class NET_IFINDEX_converter(CConverter): @@ -7403,6 +7403,9 @@ _socket_if_nameindex_impl(PyObject *module) #endif } +#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS) + +#if defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS) /*[clinic input] _socket.if_nametoindex @@ -7432,6 +7435,9 @@ _socket_if_nametoindex_impl(PyObject *module, PyObject *oname) return PyLong_FromUnsignedLong(index); } +#endif // defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS) + +#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS) /*[clinic input] @permit_long_summary @@ -7456,7 +7462,7 @@ _socket_if_indextoname_impl(PyObject *module, NET_IFINDEX index) return PyUnicode_DecodeFSDefault(name); } -#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS) +#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS) #ifdef CMSG_LEN diff --git a/configure.ac b/configure.ac index 476f13c82bbb2b9..5b29e62079319eb 100644 --- a/configure.ac +++ b/configure.ac @@ -5507,7 +5507,8 @@ AC_CHECK_FUNCS([ \ getgrnam_r getgrouplist gethostname getitimer getloadavg getlogin getlogin_r \ getpeername getpgid getpid getppid getpriority _getpty \ getpwent getpwnam_r getpwuid getpwuid_r getresgid getresuid getrusage getsid getspent \ - getspnam gettid getuid getwd grantpt if_nameindex initgroups kill killpg lchown linkat \ + getspnam gettid getuid getwd grantpt if_indextoname if_nameindex \ + if_nametoindex initgroups kill killpg lchown linkat \ lockf lstat lutimes madvise mbrtowc memrchr mkdirat mkfifo mkfifoat \ mknod mknodat mktime mmap mremap nice openat opendir pathconf pause \ pidfd_open pidfd_getfd pidfd_send_signal pipe \ From 3732ab4f3653c7a767fcd426a6e93c98520b470a Mon Sep 17 00:00:00 2001 From: A5rocks Date: Mon, 31 Aug 2026 09:01:25 -0400 Subject: [PATCH 2/6] Try addressing CI --- .../2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst | 3 +++ Modules/clinic/socketmodule.c.h | 2 +- configure | 13 ++++++++++++- pyconfig.h.in | 7 ++++++- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst diff --git a/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst b/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst new file mode 100644 index 000000000000000..ef7c9e9ee618dba --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst @@ -0,0 +1,3 @@ +Gate `socket.if_nametoindex` and `socket.if_indextoname` on their respective +OS functionality. This matters for Android, on which both are available +prior to API 24, as they are gated on ``if_nameindex`` which is not! diff --git a/Modules/clinic/socketmodule.c.h b/Modules/clinic/socketmodule.c.h index 894c5f7c641457e..dd5a906dda1a384 100644 --- a/Modules/clinic/socketmodule.c.h +++ b/Modules/clinic/socketmodule.c.h @@ -2478,4 +2478,4 @@ _socket_CMSG_SPACE(PyObject *module, PyObject *arg) #ifndef _SOCKET_CMSG_SPACE_METHODDEF #define _SOCKET_CMSG_SPACE_METHODDEF #endif /* !defined(_SOCKET_CMSG_SPACE_METHODDEF) */ -/*[clinic end generated code: output=acc30d6fdeb54e90 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=aa9082b592c39fa5 input=a9049054013a1b77]*/ diff --git a/configure b/configure index 6b560fe6841b722..01cd53a585c961e 100755 --- a/configure +++ b/configure @@ -20743,12 +20743,24 @@ if test "x$ac_cv_func_grantpt" = xyes then : printf "%s\n" "#define HAVE_GRANTPT 1" >>confdefs.h +fi +ac_fn_c_check_func "$LINENO" "if_indextoname" "ac_cv_func_if_indextoname" +if test "x$ac_cv_func_if_indextoname" = xyes +then : + printf "%s\n" "#define HAVE_IF_INDEXTONAME 1" >>confdefs.h + fi ac_fn_c_check_func "$LINENO" "if_nameindex" "ac_cv_func_if_nameindex" if test "x$ac_cv_func_if_nameindex" = xyes then : printf "%s\n" "#define HAVE_IF_NAMEINDEX 1" >>confdefs.h +fi +ac_fn_c_check_func "$LINENO" "if_nametoindex" "ac_cv_func_if_nametoindex" +if test "x$ac_cv_func_if_nametoindex" = xyes +then : + printf "%s\n" "#define HAVE_IF_NAMETOINDEX 1" >>confdefs.h + fi ac_fn_c_check_func "$LINENO" "initgroups" "ac_cv_func_initgroups" if test "x$ac_cv_func_initgroups" = xyes @@ -40179,4 +40191,3 @@ if test "$ac_cv_header_stdatomic_h" != "yes"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: Your compiler or platform does have a working C11 stdatomic.h. A future version of Python may require stdatomic.h." >&5 printf "%s\n" "$as_me: Your compiler or platform does have a working C11 stdatomic.h. A future version of Python may require stdatomic.h." >&6;} fi - diff --git a/pyconfig.h.in b/pyconfig.h.in index 64b5c52790b4581..6c110a553a6100d 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -748,9 +748,15 @@ /* Define to 1 if you have the header file. */ #undef HAVE_ICONV_H +/* Define to 1 if you have the 'if_indextoname' function. */ +#undef HAVE_IF_INDEXTONAME + /* Define to 1 if you have the 'if_nameindex' function. */ #undef HAVE_IF_NAMEINDEX +/* Define to 1 if you have the 'if_nametoindex' function. */ +#undef HAVE_IF_NAMETOINDEX + /* Define if you have the 'inet_aton' function. */ #undef HAVE_INET_ATON @@ -2279,4 +2285,3 @@ #endif #endif /*Py_PYCONFIG_H*/ - From cb9422d0a6cbcd62fbccdf18aef2b07366deb783 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Mon, 31 Aug 2026 09:23:55 -0400 Subject: [PATCH 3/6] Fix RST formatting + reword Co-authored-by: Stan Ulbrych --- .../Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst b/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst index ef7c9e9ee618dba..75ed60cc6ce6ab1 100644 --- a/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst +++ b/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst @@ -1,3 +1,3 @@ -Gate `socket.if_nametoindex` and `socket.if_indextoname` on their respective -OS functionality. This matters for Android, on which both are available -prior to API 24, as they are gated on ``if_nameindex`` which is not! +:func:`socket.if_nametoindex` and :func:`socket.if_indextoname` are now +available on platforms that provide them but not ``if_nameindex()``, such +as Android before API level 24. From 088ae311bdfc5e947b006797f87094e939a5d06d Mon Sep 17 00:00:00 2001 From: A5rocks Date: Mon, 31 Aug 2026 23:13:12 -0400 Subject: [PATCH 4/6] Readd newlines --- configure | 1 + pyconfig.h.in | 1 + 2 files changed, 2 insertions(+) diff --git a/configure b/configure index 01cd53a585c961e..b79a5587553b053 100755 --- a/configure +++ b/configure @@ -40191,3 +40191,4 @@ if test "$ac_cv_header_stdatomic_h" != "yes"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: Your compiler or platform does have a working C11 stdatomic.h. A future version of Python may require stdatomic.h." >&5 printf "%s\n" "$as_me: Your compiler or platform does have a working C11 stdatomic.h. A future version of Python may require stdatomic.h." >&6;} fi + diff --git a/pyconfig.h.in b/pyconfig.h.in index 6c110a553a6100d..47f60250dae1f49 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -2285,3 +2285,4 @@ #endif #endif /*Py_PYCONFIG_H*/ + From f6fe9aa5b5c16f9c3284a590e4c5554e40be40c9 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Mon, 31 Aug 2026 23:15:42 -0400 Subject: [PATCH 5/6] One final rewording for newsfragment --- .../Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst b/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst index 75ed60cc6ce6ab1..a3245ea6e650373 100644 --- a/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst +++ b/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst @@ -1,3 +1,3 @@ :func:`socket.if_nametoindex` and :func:`socket.if_indextoname` are now -available on platforms that provide them but not ``if_nameindex()``, such -as Android before API level 24. +available on platforms that provide them but not +:func:`socket.if_nameindex`, such as Android before API level 24. From c37a80aa49175fc243f26d5e55d1a20c54ee24d7 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Tue, 1 Sep 2026 18:31:41 -0400 Subject: [PATCH 6/6] Update 2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst Co-authored-by: Stan Ulbrych --- .../next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst b/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst index a3245ea6e650373..056b54fd12aeda3 100644 --- a/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst +++ b/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst @@ -1,3 +1,3 @@ :func:`socket.if_nametoindex` and :func:`socket.if_indextoname` are now available on platforms that provide them but not -:func:`socket.if_nameindex`, such as Android before API level 24. +``if_nameindex``, such as Android before API level 24.