Linux的让所有的网络接口名称 [英] Linux getting all network interface names

查看:138
本文介绍了Linux的让所有的网络接口名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要收集所有的接口名,甚至不涨的时刻的人。像使用ifconfig -a

I need to collect all the interface names, even the ones that aren't up at the moment. Like ifconfig -a.

getifaddr()通过相同的接口名称多次迭代。我怎么能收集所有的接口名只有一次使用 getifaddr()

getifaddr() is iterating through same interface name multiple times. How can I collect all the interface names just once using getifaddr()?

推荐答案

您可以检查哪些条目从getifaddrs属于AF_PACKET家庭。在我的系统似乎列出所有接口:

You could check which entries from getifaddrs belong to the AF_PACKET family. On my system that seems to list all interfaces:

struct ifaddrs *addrs,*tmp;

getifaddrs(&addrs);
tmp = addrs;

while (tmp)
{
    if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_PACKET)
        printf("%s\n", tmp->ifa_name);

    tmp = tmp->ifa_next;
}

freeifaddrs(addrs);

这篇关于Linux的让所有的网络接口名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆