You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
socket.if_nametoindex('no-such-iface') raises OSError() without setting errno #100218
changed the title [-]socket.if_nametoindex('no-such-iface') raises OSError() wothout setting errno[/-][+]socket.if_nametoindex('no-such-iface') raises OSError() without setting errno[/+]on Dec 13, 2022
On success, if_nametoindex() returns the index number of the network interface;
on error, 0 is returned and errno is set to indicate the error.
It MUST set errno on error! I think there was some incorrect libc implementation when the code was written. So, a crutch like the one I described before is not ever required. As a solution, we can do the following :
errno=ENOENT; // for buggy if_nametoindex implementations, where they don't set errno.index=if_nametoindex(PyBytes_AS_STRING(oname));
Py_DECREF(oname);
if (index==0) {
PyErr_SetFromErrno(PyExc_OSError);
returnNULL;
}
Sorry, I am not qualified enought in this module to make decisions :)
I've just highlighted that this is a known thing. Probably, you can go to the original comment PR and try to figure out what were the alternatives.
changed the title [-]socket.if_nametoindex('no-such-iface') raises OSError() without setting errno[/-][+]`socket.if_nametoindex('no-such-iface')` raises OSError() without setting errno[/+]on Nov 9, 2025
changed the title [-]`socket.if_nametoindex('no-such-iface')` raises OSError() without setting errno[/-][+]`socket.if_nametoindex('no-such-iface')` raises `OSError()` without setting `errno`[/+]on Nov 9, 2025
Activity
[-]socket.if_nametoindex('no-such-iface') raises OSError() wothout setting errno[/-][+]socket.if_nametoindex('no-such-iface') raises OSError() without setting errno[/+]sobolevn commentedon Dec 13, 2022
There's a comment in the source code:
/* if_nametoindex() doesn't set errno */socketpair commentedon Dec 13, 2022
Then it should not be
OSErroror it has to set some errno, like ENOENT or so.Another example from the same file:
I propose the same change. i.e.
errno= ENOENT+PyErr_SetFromErrno(PyExc_OSError);socketpair commentedon Dec 13, 2022
man if_nametoindex:It MUST set errno on error! I think there was some incorrect libc implementation when the code was written. So, a crutch like the one I described before is not ever required. As a solution, we can do the following :
socketpair commentedon Dec 13, 2022
@sobolevn
sobolevn commentedon Dec 13, 2022
Sorry, I am not qualified enought in this module to make decisions :)
I've just highlighted that this is a known thing. Probably, you can go to the original comment PR and try to figure out what were the alternatives.
arhadthedev commentedon Feb 3, 2023
cc @gpshead as a network expert.
vstinner commentedon Nov 8, 2025
@socketpair: Ping on an old issue (!). What is your operating system? I cannot reproduce the issue on Linux.
picnixz commentedon Nov 8, 2025
FTR, I was able to reproduce this on an OpenSUSE 15.5 with Kernel 5.14.21-150500.55.88-default and libc 2.31.
socketpair commentedon Nov 8, 2025
Yes, it was linux x86, Fedora, but I don't know exact Fedora version and Python version
[-]socket.if_nametoindex('no-such-iface') raises OSError() without setting errno[/-][+]`socket.if_nametoindex('no-such-iface')` raises OSError() without setting errno[/+][-]`socket.if_nametoindex('no-such-iface')` raises OSError() without setting errno[/-][+]`socket.if_nametoindex('no-such-iface')` raises `OSError()` without setting `errno`[/+]gh-100218: correctly set `errno` when `socket.if_{nametoindex,indexto…
pythongh-100218: correctly set `errno` when `socket.if_{nametoindex,i…
[3.13] pythongh-100218: correctly set `errno` when `socket.if_{nameto…
[3.14] gh-100218: correctly set `errno` when `socket.if_{nametoindex,…
[3.13] gh-100218: correctly set `errno` when `socket.if_{nametoindex,…
pythongh-100218: correctly set `errno` when `socket.if_{nametoindex,i…