23,121
社区成员
发帖
与我相关
我的任务
分享
int get_netportstatus(const char *interface) {
char cmd[1024];
char *tt;
FILE *fp;
int devflag;
devflag=get_netflag(interface);
if (devflag==DEV_DOWN) {
sprintf(cmd,"ifconfig %s up",interface);
system(cmd);
}
sprintf(cmd,"ethtool %s | grep \"Link detected\" > /tmp/eth.temp",interface);
system(cmd);
if (devflag==DEV_DOWN) {
sprintf(cmd,"ifconfig %s down",interface);
system(cmd);
}
fp=fopen("/tmp/eth.temp","r");
if (fp==NULL) {
system("rm -rf /tmp/eth.temp");
return -1;
}
fgets(cmd,1024,fp);
fclose(fp);
system("rm -rf /tmp/eth.temp");
tt=strstr(cmd,"no");
if (tt!=NULL) return LINK_DOWN;
tt=strstr(cmd,"yes");
if (tt!=NULL) return LINK_UP;
return -1;
}