diff options
Diffstat (limited to 'server/InterfaceController.cpp')
| -rw-r--r-- | server/InterfaceController.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/server/InterfaceController.cpp b/server/InterfaceController.cpp index 28b814f2..5a630255 100644 --- a/server/InterfaceController.cpp +++ b/server/InterfaceController.cpp @@ -17,6 +17,7 @@ #include <dirent.h> #include <errno.h> #include <malloc.h> +#include <net/if.h> #include <sys/socket.h> #include <functional> @@ -386,3 +387,22 @@ void InterfaceController::setIPv6OptimisticMode(const char *value) { setOnAllInterfaces(ipv6_proc_path, "optimistic_dad", value); setOnAllInterfaces(ipv6_proc_path, "use_optimistic", value); } + +StatusOr<std::map<std::string, uint32_t>> InterfaceController::getIfaceList() { + std::map<std::string, uint32_t> ifacePairs; + DIR* d; + struct dirent* de; + + if (!(d = opendir("/sys/class/net"))) { + return statusFromErrno(errno, "Cannot open iface directory"); + } + while ((de = readdir(d))) { + if (de->d_name[0] == '.') continue; + uint32_t ifaceIndex = if_nametoindex(de->d_name); + if (ifaceIndex) { + ifacePairs.insert(std::pair<std::string, uint32_t>(de->d_name, ifaceIndex)); + } + } + closedir(d); + return ifacePairs; +} |
