Skip to content

gh-156439: Gate socket.if_{nametoindex, indextoname} on respective OS capability - #156708

Merged
StanFromIreland merged 8 commits into
python:mainfrom
A5rocks:socket-configure
Sep 3, 2026
Merged

gh-156439: Gate socket.if_{nametoindex, indextoname} on respective OS capability#156708
StanFromIreland merged 8 commits into
python:mainfrom
A5rocks:socket-configure

Conversation

@A5rocks

@A5rocks A5rocks commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

I'm not exactly a C programmer so hopefully I'm approaching this the correct way?

@bedevere-app

bedevere-app Bot commented Aug 31, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot

python-cla-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Comment thread pyconfig.h.in
Comment thread Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst Outdated
Co-authored-by: Stan Ulbrych <stan@python.org>
@StanFromIreland StanFromIreland changed the title gh-156439: Gate socket.if_{nametoindex, indextoname} on respective OS capability gh-156439: Gate socket.if_{nametoindex, indextoname} on respective OS capability Aug 31, 2026
@StanFromIreland StanFromIreland changed the title gh-156439: Gate socket.if_{nametoindex, indextoname} on respective OS capability gh-156439: Gate socket.if_{nametoindex, indextoname} on respective OS capability Aug 31, 2026
Comment thread Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst Outdated
Co-authored-by: Stan Ulbrych <stan@python.org>
Comment thread Modules/socketmodule.c
Comment thread Modules/socketmodule.c
# define NET_IFINDEX unsigned int
# endif
#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)
#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is mismatched, but I also don't see why we need HAVE_IF_NAMETOINDEX? I understand this was @mhsmith 's suggestion, can you please clarify why? From my understanding, it's not necessary, the NET_IFINDEX/_PyLong_NetIfindex_Converter definitions are only needed by if_indextoname.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in the function body:

cpython/Modules/socketmodule.c

Lines 7418 to 7423 in e0afadb

static PyObject *
_socket_if_nametoindex_impl(PyObject *module, PyObject *oname)
/*[clinic end generated code: output=289a411614f30244 input=6125dc20683560cf]*/
{
#ifdef MS_WINDOWS
NET_IFINDEX index;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless that's something that's defined in the Windows headers?

@StanFromIreland StanFromIreland Sep 3, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless that's something that's defined in the Windows headers?

From what I can tell, it's defined by Iphlpapi.h on Windows (see docs for if_indextoname). As such, it's conditional on #ifdef MS_WINDOWS. Adding HAVE_IF_NAMETOINDEX makes no difference here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, reverted. Sorry about that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries!

@StanFromIreland
StanFromIreland merged commit cb54488 into python:main Sep 3, 2026
55 checks passed
@StanFromIreland

Copy link
Copy Markdown
Member

Merged, thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

It's possible to have if_indextoname and if_nametoindex without if_nameindex, but socket doesn't expose that

3 participants