I need to check periodically if an network adapter is present under windows, I tried with GetInterfaceInfo
but it doesn't return the "name" like "Local area connection 1" (that I need) but a long ID.
I also find that code (here):
bool is_interface_online(std::string interface) {
struct ifreq ifr;
int sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, interface.c_str());
if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
perror("SIOCGIFFLAGS");
}
close(sock);
return !!(ifr.ifr_flags & IFF_UP);
}
But I can't port it to work on windows.
I also have a perfect command:
wmic NIC get NetConnectionID
But in c++ it seems that I need to write to a file first to read the result of the command (with ShellExecute
), and as I will check maybe every second, I want to avoid disk operations.