Skip to content

Commit cb54488

Browse files
A5rocksStanFromIrelandmhsmith
authored
gh-156439: Gate socket.if_{nametoindex, indextoname} on respective OS capability (#156708)
Co-authored-by: Stan Ulbrych <stan@python.org> Co-authored-by: Malcolm Smith <smith@chaquo.com>
1 parent c8ea867 commit cb54488

6 files changed

Lines changed: 37 additions & 9 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:func:`socket.if_nametoindex` and :func:`socket.if_indextoname` are now
2+
available on platforms that provide them but not
3+
``if_nameindex``, such as Android before API level 24.

Modules/clinic/socketmodule.c.h

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/socketmodule.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,14 +631,14 @@ _PyLong_##NAME##_Converter(PyObject *obj, void *ptr) \
631631
return 1; \
632632
}
633633

634-
#if defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)
634+
#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)
635635
# ifdef MS_WINDOWS
636636
UNSIGNED_INT_CONVERTER(NetIfindex, NET_IFINDEX)
637637
# else
638638
# define _PyLong_NetIfindex_Converter _PyLong_UnsignedInt_Converter
639639
# define NET_IFINDEX unsigned int
640640
# endif
641-
#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)
641+
#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)
642642

643643
/*[python input]
644644
class NET_IFINDEX_converter(CConverter):
@@ -7403,6 +7403,9 @@ _socket_if_nameindex_impl(PyObject *module)
74037403
#endif
74047404
}
74057405

7406+
#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)
7407+
7408+
#if defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS)
74067409

74077410
/*[clinic input]
74087411
_socket.if_nametoindex
@@ -7432,6 +7435,9 @@ _socket_if_nametoindex_impl(PyObject *module, PyObject *oname)
74327435
return PyLong_FromUnsignedLong(index);
74337436
}
74347437

7438+
#endif // defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS)
7439+
7440+
#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)
74357441

74367442
/*[clinic input]
74377443
@permit_long_summary
@@ -7456,7 +7462,7 @@ _socket_if_indextoname_impl(PyObject *module, NET_IFINDEX index)
74567462
return PyUnicode_DecodeFSDefault(name);
74577463
}
74587464

7459-
#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)
7465+
#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)
74607466

74617467

74627468
#ifdef CMSG_LEN

configure

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5528,7 +5528,8 @@ AC_CHECK_FUNCS([ \
55285528
getgrnam_r getgrouplist gethostname getitimer getloadavg getlogin getlogin_r \
55295529
getpeername getpgid getpid getppid getpriority _getpty \
55305530
getpwent getpwnam_r getpwuid getpwuid_r getresgid getresuid getrusage getsid getspent \
5531-
getspnam gettid getuid getwd grantpt if_nameindex initgroups kill killpg lchown linkat \
5531+
getspnam gettid getuid getwd grantpt if_indextoname if_nameindex \
5532+
if_nametoindex initgroups kill killpg lchown linkat \
55325533
lockf lstat lutimes madvise mbrtowc memrchr mkdirat mkfifo mkfifoat \
55335534
mknod mknodat mktime mmap mremap nice openat opendir pathconf pause \
55345535
pidfd_open pidfd_getfd pidfd_send_signal pipe \

pyconfig.h.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,15 @@
751751
/* Define to 1 if you have the <iconv.h> header file. */
752752
#undef HAVE_ICONV_H
753753

754+
/* Define to 1 if you have the 'if_indextoname' function. */
755+
#undef HAVE_IF_INDEXTONAME
756+
754757
/* Define to 1 if you have the 'if_nameindex' function. */
755758
#undef HAVE_IF_NAMEINDEX
756759

760+
/* Define to 1 if you have the 'if_nametoindex' function. */
761+
#undef HAVE_IF_NAMETOINDEX
762+
757763
/* Define if you have the 'inet_aton' function. */
758764
#undef HAVE_INET_ATON
759765

0 commit comments

Comments
 (0)