-
-
Notifications
You must be signed in to change notification settings - Fork 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
Workaround to ignore interfaces whose name got truncated by netstat #149
Conversation
While a fix to #147 is really important, I am not a big fan of ignoring truncated interface names. It should be the ultimate solution. We are still working on a good way to add unit tests to functions such as read_routes(). PR #127 fixes read_routes6() on OS X and add unit tests to other platforms using the mock module. |
May be try netiface for that problem? |
When interface names are longer than 7 characters netstat will truncate them to the first 7 chars which leads to looking up an invalid interface name. We attempt to guess the name of the interface based on the output of ifconfig -l. If there is only one candate we consider that otherwise we ignore it.
Rebased and pushed with support for guessing the interface name. |
e702467
to
9144c8c
Compare
return it. If there are none or more, then we return None. | ||
""" | ||
f = os.popen('ifconfig -l') | ||
ifaces = f.readlines()[0].strip().split(' ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inefficient. Maybe this would be better?
from __future__ import with_statement
[...]
with os.popen('ifconfig -l') as fdesc:
ifaces = fdesc.readline().strip().split()
for iface in ifaces:
if iface.startswith(netif):
return iface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I can change to use the with statement.
Regarding:
for iface in ifaces:
if iface.startswith(netif):
return iface
I want to avoid returning an interface name when there are multiple matches as that means that I am actually not sure what interface is the correct one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Anyway, please avoid filter
+ lambda
: matches = [iface for iface in ifaces if iface.startswith(netif)]
Yes this fixes my bug |
# This means the interface name is probably truncated by | ||
# netstat -nr. We attempt to guess it's name and if not we | ||
# ignore it. | ||
netif = _guess_iface_name(netif) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be interesting to assign the returned value to fixed_netif in order to display a correct warning. See @Osso comment.
Thanks. |
I bet it is broken too but the default vagrant configuration is without ipv6. |
@hellais could you apply my comment ? |
Due to no recent activity on this PR, I modified the original patch and created PR #260. |
When interface names are longer than 7 characters netstat will truncate
them to the first 7 chars which leads to looking up an invalid interface
name.
This workaround ignores interfaces that are too long.
This fixes #147