MCPcopy Create free account
hub / github.com/PiSCSI/piscsi / IsInterfaceUp

Method IsInterfaceUp

cpp/shared/network_util.cpp:22–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20using namespace std;
21
22bool network_util::IsInterfaceUp(const string& interface)
23{
24 ifreq ifr = {};
25 strncpy(ifr.ifr_name, interface.c_str(), IFNAMSIZ - 1); //NOSONAR Using strncpy is safe
26 const int fd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
27
28 if (!ioctl(fd, SIOCGIFFLAGS, &ifr) && (ifr.ifr_flags & IFF_UP)) {
29 close(fd);
30 return true;
31 }
32
33 close(fd);
34 return false;
35}
36
37set<string, less<>> network_util::GetNetworkInterfaces()
38{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected