Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cpputil/ifconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int ifconfig(std::vector<ifconfig_t>& 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);
Expand Down Expand Up @@ -125,6 +126,7 @@ int ifconfig(std::vector<ifconfig_t>& 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));
Expand Down Expand Up @@ -167,6 +169,7 @@ int ifconfig(std::vector<ifconfig_t>& ifcs) {
#elif defined(OS_MAC)
#include <ifaddrs.h>
#include <net/if_dl.h>
#include <net/if.h>
int ifconfig(std::vector<ifconfig_t>& ifcs) {
struct ifaddrs *ifas, *ifap;
int ret = getifaddrs(&ifas);
Expand All @@ -185,6 +188,7 @@ int ifconfig(std::vector<ifconfig_t>& 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
Expand Down
1 change: 1 addition & 0 deletions cpputil/ifconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#endif

typedef struct ifconfig_s {
unsigned int ifindex;
char name[128];
char ip[16];
char mask[16];
Expand Down
Loading