+// Check whether the specified interface is up.
+bool interfaceIsUp(const char* name) {
+ if (name == nullptr) return false;
+ struct ifreq ifr = {};
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ int sock = socket(AF_INET6, SOCK_DGRAM, 0);
+ if (sock == -1) return false;
+ int ret = ioctl(sock, SIOCGIFFLAGS, &ifr, sizeof(ifr));
+ close(sock);
+ return (ret == 0) && (ifr.ifr_flags & IFF_UP);
+}
+