获取网卡名称 linux c
来源:互联网 发布:淘宝运营黑科技 编辑:程序博客网 时间:2024/05/21 03:59
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <net/if.h>
#include <sys/ioctl.h>
int main()
{
int i=0;
int sockfd;
struct ifconf ifc;
unsigned char buf[512];
struct ifreq *ifr;
//初始化ifconf
ifc.ifc_len = 512;
ifc.ifc_buf = buf;
if((sockfd = socket(AF_INET, SOCK_DGRAM, 0))<0)
{
perror("socket");
exit(1);
}
ioctl(sockfd, SIOCGIFCONF, &ifconf); //获取所有接口信息
//接下来获取逐个网卡的名称和IP地址
ifr = (struct ifreq*)buf;
for(i=(ifc.ifc_len/sizeof(struct ifreq)); i>0; i--)
{
printf("name = [%s]\n", ifreq->ifr_name);
}
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <net/if.h>
#include <sys/ioctl.h>
int main()
{
int i=0;
int sockfd;
struct ifconf ifc;
unsigned char buf[512];
struct ifreq *ifr;
//初始化ifconf
ifc.ifc_len = 512;
ifc.ifc_buf = buf;
if((sockfd = socket(AF_INET, SOCK_DGRAM, 0))<0)
{
perror("socket");
exit(1);
}
ioctl(sockfd, SIOCGIFCONF, &ifconf); //获取所有接口信息
//接下来获取逐个网卡的名称和IP地址
ifr = (struct ifreq*)buf;
for(i=(ifc.ifc_len/sizeof(struct ifreq)); i>0; i--)
{
printf("name = [%s]\n", ifreq->ifr_name);
printf("local addr = [%s]\n", inet_ntoa(((struct sockaddr_in*)&(ifreq->ifr_addr))->sin_addr));
ifr++;
}
return 0;}
阅读全文
1 1
- 获取网卡名称 linux c
- Linux修改网卡名称
- 修改linux网卡名称
- linux修改网卡名称
- 获取所有网卡的名称
- 多网卡下获取网卡名称
- linux c获取系统网卡信息
- linux修改网卡设备名称
- Linux 修改 网卡名称 小记
- Linux 修改 网卡名称 小记
- 【Linux】redhat6 更改网卡名称
- linux RHEL 修改网卡名称
- linux下修改网卡名称
- Linux 修改 网卡名称 小记
- linux 6 网卡名称修改
- Linux更改网卡逻辑名称
- Linux系统网卡名称固化
- c#获取主机名称网卡MACIP地址
- 管道的原子性
- Poj
- JavaScript立即执行函数
- opnet平台中切换模块的理解——切换的建模
- 条款 49
- 获取网卡名称 linux c
- 3ds max 显示物品大纲,方便修改名称
- 12 WebGL 着色器编程语言GLSL ES的全局变量和局部变量
- CentOS 7.2 安装和配置 FTP 服务器
- 图片的上传和预览(上传到oracle数据库)
- AngularJS杂记2----表达式
- 元类型之Q_DECLARE_METATYPE
- Spark RDD API详解(一) Map和Reduce
- redis外网连接