fedora-python / python-ethtool

Deprecated Python bindings for the ethtool kernel interface
GNU General Public License v2.0
15 stars 13 forks source link

Fix issue when interface has no IPv4 address assigned. #52

Closed frenzymadness closed 6 years ago

frenzymadness commented 6 years ago

pifconfig crashes when tries to print info about an interface with no IPv4 address assigned.

For example, I have two interfaces, one without IPv4 address:

$ ip addr show dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
$ ip addr show dev enp0s31f6
2: enp0s31f6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 50:7b:9d:e6:53:38 brd ff:ff:ff:ff:ff:ff

pifconfig crashes when it comes to printing info about the second interface:

$ ./pifconfig 
lo
    inet addr:127.0.0.1
    Mask:255.0.0.0
    inet6 addr: ::1/128 Scope: host
    UP LOOPBACK RUNNING

** ERROR ** [Device enp0s31f6]: [Errno 99] Cannot assign requested address

After this change, it omits info about IPV4 address/network/broadcast when it cannot get it from OS:

$ ./pifconfig 
lo
    inet addr:127.0.0.1
    Mask:255.0.0.0
    inet6 addr: ::1/128 Scope: host
    UP LOOPBACK RUNNING

enp0s31f6
    HWaddr 50:7b:9d:e6:53:38
    UP BROADCAST MULTICAST