diff --git a/cpputil/ifconfig.cpp b/cpputil/ifconfig.cpp index 6aaeec8b9..3e65b1fdc 100644 --- a/cpputil/ifconfig.cpp +++ b/cpputil/ifconfig.cpp @@ -39,6 +39,7 @@ int ifconfig(std::vector& ifcs) { ifcs.clear(); ifconfig_t tmp; for (int i = 0; i < cnt; ++i) { + tmp.ifindex = if_nametoindex(ifc.ifc_req[i].ifr_name); // name strcpy(ifr.ifr_name, ifc.ifc_req[i].ifr_name); //printf("name: %s\n", ifr.ifr_name); @@ -125,6 +126,7 @@ int ifconfig(std::vector& ifcs) { pAddr->PhysicalAddress[5]); memset(&ifc, 0, sizeof(ifc)); + ifc.ifindex = pAddr->IfIndex; strncpy(ifc.name, pAddr->AdapterName, sizeof(ifc.name)); strncpy(ifc.ip, "0.0.0.0", sizeof(ifc.ip)); strncpy(ifc.mask, "255.255.255.255", sizeof(ifc.mask)); @@ -167,6 +169,7 @@ int ifconfig(std::vector& ifcs) { #elif defined(OS_MAC) #include #include +#include int ifconfig(std::vector& ifcs) { struct ifaddrs *ifas, *ifap; int ret = getifaddrs(&ifas); @@ -185,6 +188,7 @@ int ifconfig(std::vector& ifcs) { continue; } memset(&tmp, 0, sizeof(tmp)); + tmp.ifindex = if_nametoindex(ifap->ifa_name); strncpy(tmp.name, ifap->ifa_name, sizeof(tmp.name)); strncpy(tmp.ip, ip, sizeof(tmp.ip)); // netmask diff --git a/cpputil/ifconfig.h b/cpputil/ifconfig.h index cf717d089..30fc65609 100644 --- a/cpputil/ifconfig.h +++ b/cpputil/ifconfig.h @@ -11,6 +11,7 @@ #endif typedef struct ifconfig_s { + unsigned int ifindex; char name[128]; char ip[16]; char mask[16];