diff options
| author | Michael Stapelberg | 2015-11-16 22:41:18 +0100 | 
|---|---|---|
| committer | Michael Stapelberg | 2015-11-16 22:41:18 +0100 | 
| commit | 3e14e6e5f3a50f670024e4204f2c0cf15f05b199 (patch) | |
| tree | ee868199fcff9ea0573603b57408049fda9fd7ed | |
| parent | Merge pull request #77 from StefaBa/master (diff) | |
first_eth_interface: ignore MAC addresses, look for IPv4/IPv6 addresses
| -rw-r--r-- | src/first_network_device.c | 7 | 
1 files changed, 7 insertions, 0 deletions
| diff --git a/src/first_network_device.c b/src/first_network_device.c index 35cd4ff..16f23e0 100644 --- a/src/first_network_device.c +++ b/src/first_network_device.c @@ -23,6 +23,13 @@ const char *first_eth_interface(const net_type_t type) {           addrp = addrp->ifa_next) {          if (strncasecmp("lo", addrp->ifa_name, strlen("lo")) == 0)              continue; +        if (addrp->ifa_addr == NULL) +            continue; +        // Skip PF_PACKET addresses (MAC addresses), as they are present on any +        // ethernet interface. +        if (addrp->ifa_addr->sa_family != AF_INET && +            addrp->ifa_addr->sa_family != AF_INET6) +            continue;          // Skip this interface if it is a wireless interface.          snprintf(path, sizeof(path), "/sys/class/net/%s/wireless", addrp->ifa_name);          const bool is_wireless = (stat(path, &stbuf) == 0); | 
