检测哪个网卡在运行
#include
#include
#include
#include
#include
#include
int check_nic(char *szName)
{
int fd;
int nRet;
struct ifreq ifr;
fd = socket(AF_INET, SOCK_DGRAM, 0);
if(fd < 0)
return -1;
strcpy(ifr.ifr_name, szName);
nRet = ioctl(fd, SIOCGIFFLAGS, &ifr);
if(nRet != 0)
goto err;
if(ifr.ifr_flags & IFF_RUNNING)
return 0;
err:
close(fd);
return -1;
}
int main(int argc, char *argv[])
{
int nRet;
nRet = check_nic("eth1");
printf("nRet=%d\n", nRet);
return 0;
}
阅读(569) | 评论(0) | 转发(0) |