Chinaunix首页 | 论坛 | 博客
  • 博客访问: 45177
  • 博文数量: 14
  • 博客积分: 1485
  • 博客等级: 上尉
  • 技术积分: 160
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-13 15:44
文章分类

全部博文(14)

文章存档

2012年(1)

2011年(2)

2010年(3)

2009年(8)

我的朋友

分类: LINUX

2010-09-26 17:08:37

检测哪个网卡在运行
 
#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;
}
阅读(538) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~