diff --git a/linux/netdev.c b/linux/netdev.c index 45b9ed0..0beb14c 100644 --- a/linux/netdev.c +++ b/linux/netdev.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "netdev.h" #include "platform.h" @@ -146,3 +147,22 @@ bool netdev_set_up_promisc(const char *const ifname, bool up, bool promisc) close(fd); return true; } + +bool netdev_check_if_exists(const char *const ifname) +{ + struct ifaddrs *ifaddr, *ifa; + bool found = false; + + if (getifaddrs(&ifaddr) == -1) { + LOG_WARN("can not check interface names, continuing"); + return true; + } + for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + if (strcmp(ifa->ifa_name, ifname) == 0) { + found = true; + break; + } + } + freeifaddrs(ifaddr); + return found; +} diff --git a/linux/netdev.h b/linux/netdev.h index c04055e..102ca2a 100644 --- a/linux/netdev.h +++ b/linux/netdev.h @@ -36,6 +36,8 @@ bool netdev_set_ip_address(const char* ifname, uint32_t ip); bool netdev_set_up_promisc(const char *const ifname, bool up, bool promisc); +bool netdev_check_if_exists(const char *const ifname); + #ifdef __cplusplus } #endif