Linux下检测网络状态是否正常
// Linux下檢測(cè)網(wǎng)絡(luò)狀態(tài)是否正常#include <sys/types.h> #include <string.h> #include <stdlib.h> #include <sys/ioctl.h> #include <stdio.h> #include <errno.h> #include <net/if.h>struct ethtool_value {__uint32_t cmd;__uint32_t data; };int main(int argc, char* argv[]) {struct ethtool_value edata;int fd = -1, err = 0;struct ifreq ifr;memset(&ifr, 0, sizeof(ifr));strcpy(ifr.ifr_name, "eth0");fd = socket(AF_INET, SOCK_DGRAM, 0);if (fd < 0) {perror("Cannot get control socket");return 70;}edata.cmd = 0x0000000a;ifr.ifr_data = (caddr_t)&edata;err = ioctl(fd, 0x8946, &ifr);if (err == 0) {fprintf(stdout, "Link detected: %s/n",edata.data ? "yes":"no");} else if (errno != EOPNOTSUPP) {perror("Cannot get link status");}return 0; }
總結(jié)
以上是生活随笔為你收集整理的Linux下检测网络状态是否正常的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 全国30m精度土壤类型分布矢量数据、土壤
- 下一篇: linux系统安装红蜘蛛,在linux