linux获取网络接口名:如eth0
来源:互联网 发布:灵活就业退休金咋算法 编辑:程序博客网 时间:2024/06/05 13:17
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<net/if.h>
static char *bad_interface_names[] = {
"lo:",
"lo",
"stf", /* pseudo-device 6to4 tunnel interface */
"gif", /* psuedo-device generic tunnel interface */
"dummy",
"vmnet",
NULL /* last entry must be NULL */
};
static int is_bad_interface_name(char *i) {
char **p;
for (p = bad_interface_names; *p; ++p)
if (strncmp(i, *p, strlen(*p)) == 0)
return 1;
return 0;
}
/* This finds the first interface which is up and is not the loopback
* interface or one of the interface types listed in bad_interface_names. */
static char *get_first_interface(void) {
struct if_nameindex * nameindex;
char *i = NULL;
int j = 0;
/* Use if_nameindex(3) instead? */
nameindex = if_nameindex();
if(nameindex == NULL) {
return NULL;
}
while(nameindex[j].if_index != 0) {
if (strcmp(nameindex[j].if_name, "lo") != 0 && !is_bad_interface_name(nameindex[j].if_name)) {
//i = xstrdup(nameindex[j].if_name);
break;
}
j++;
}
if_freenameindex(nameindex);
return i;
}
struct if_nameindex {
unsigned int if_index;
char *if_name;
};//结构提
- linux获取网络接口名:如eth0
- linux下网络名eth0 更改
- Linux网络接口配置文件ifcfg-eth0解析
- Linux网络接口配置文件ifcfg-eth0解析
- Linux网络接口配置文件ifcfg-eth0解析
- linux网络配置相关命令、虚拟网络接口eth0:0
- 根据网络接口名获取IP地址
- linux eth0 网络笔记
- Linux网卡名改eth0方法
- Android 通过 JNI 获取 Wi-Fi 网络接口名
- 关闭eth0或者某个网络接口
- LINUX下网络配置-network eth0 ifconfig
- vm centos linux网络配置ifcfg-eth0
- linux c 命令 获取eth0 ip地址
- Linux网络编程系列-获取机器名和ip
- Linux网络编程系列-获取机器名和ip
- 用反射获取接口名
- Linux系统 C++ 获取网络接口,以及主机网关IP
- Maven配置资料(二)
- Cognos会话缓存设置(展现实时数据)
- JS中常用的xpath特性
- poj1503
- 用 chukeh.dll 实现 web 端的多线程操作
- linux获取网络接口名:如eth0
- MSDN WebCast网络广播下载列表
- SQL SERVER的ROWCOUNT关键字
- 关于产生服从U(0,1)的随机数的过程
- 下载的sql大全,不敢独享,特此呈上
- 开始收集.net面试题
- 凭什么来爱你 我的技术...
- div动态展开和关闭
- Spring中的IOC(一):什么是IOC及Spring中实现IOC的方式(依赖注入)