diff options
author | Ingo Bürk <admin@airblader.de> | 2017-04-16 07:43:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-16 07:43:30 +0200 |
commit | 0e406a1f3b6b6b00f78aea838cc4396b0584d085 (patch) | |
tree | 28ecb9aa05c6f8ea0d750b7108ac30af2b8dcc81 /src | |
parent | c7dea747519f99584002084df3dce546f37df8b5 (diff) | |
parent | 6a19709e65c6aac2085962e989f2429c539c5af5 (diff) |
Merge pull request #219 from flammi/master
Add check for virtual ethernet devices
Diffstat (limited to 'src')
-rw-r--r-- | src/first_network_device.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/first_network_device.c b/src/first_network_device.c index 5932385..3f34cf2 100644 --- a/src/first_network_device.c +++ b/src/first_network_device.c @@ -50,6 +50,22 @@ static bool sysfs_devtype(char *dest, size_t n, const char *ifnam) { return true; } +static bool is_virtual(const char *ifname) { + char path[1024]; + char *target = NULL; + bool is_virtual = false; + + snprintf(path, sizeof(path), "/sys/class/net/%s", ifname); + if ((target = realpath(path, NULL))) { + if (BEGINS_WITH(target, "/sys/devices/virtual/")) { + is_virtual = true; + } + } + + free(target); + return is_virtual; +} + static net_type_t iface_type(const char *ifname) { #ifdef __linux__ char devtype[32]; @@ -57,6 +73,7 @@ static net_type_t iface_type(const char *ifname) { if (!sysfs_devtype(devtype, sizeof(devtype), ifname)) return NET_TYPE_OTHER; + /* Default to Ethernet when no devtype is available */ if (!devtype[0]) return NET_TYPE_ETHERNET; @@ -147,6 +164,8 @@ const char *first_eth_interface(const net_type_t type) { iftype = iface_type(addrp->ifa_name); if (iftype != type) continue; + if (is_virtual(addrp->ifa_name)) + continue; interface = strdup(addrp->ifa_name); break; } |