int detect_ethtool(char *ifname) { int skfd; if (( skfd = socket( AF_INET, SOCK_DGRAM, 0 ) ) < 0 ) { printf("[ETHTOOL]:socket error\n"); return 2; } struct ifreq ifr; struct ethtool_value edata; memset(&ifr, 0, sizeof(ifr)); edata.cmd = ETHTOOL_GLINK; strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)-1); ifr.ifr_data = (char *) &edata; if (ioctl(skfd, SIOCETHTOOL, &ifr) == -1) { printf("[ETHTOOL]ETHTOOL_GLINK failed: %s\n", strerror(errno)); close(skfd); return 2; } close(skfd); return (edata.data ? 0 : 1); }