-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
socket.if_nametoindex('no-such-iface') raises OSError() without setting errno #100218
Comments
There's a comment in the source code: |
Then it should not be static PyObject *
socket_if_nametoindex(PyObject *self, PyObject *args)
{
PyObject *oname;
#ifdef MS_WINDOWS
NET_IFINDEX index;
#else
unsigned long index;
#endif
if (!PyArg_ParseTuple(args, "O&:if_nametoindex",
PyUnicode_FSConverter, &oname))
return NULL;
index = if_nametoindex(PyBytes_AS_STRING(oname));
Py_DECREF(oname);
if (index == 0) {
/* if_nametoindex() doesn't set errno */
PyErr_SetString(PyExc_OSError, "no interface with this name");
return NULL;
}
return PyLong_FromUnsignedLong(index);
} Another example from the same file: if (h->h_addrtype != af) {
/* Let's get real error message to return */
errno = EAFNOSUPPORT;
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
} I propose the same change. i.e. |
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);
return NULL;
} |
Sorry, I am not qualified enought in this module to make decisions :) |
cc @gpshead as a network expert. |
I think it's a bug because I can not distinguish from any other OS errors precisely (like EPERM vs ENOENT or so)
The text was updated successfully, but these errors were encountered: