gpt4 book ai didi

c++ - 如何以编程方式检索 eth0 id

转载 作者:太空宇宙 更新时间:2023-11-04 01:05:08 25 4
gpt4 key购买 nike

当我给/sbin/ip addr show 在我的 Linux 机器上。我得到如下输出

3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:00:21:02:16:6b brd ff:ff:ff:ff:ff:ff .. so on

如何在 C 或 CPP 中以编程方式为 eth0 检索上述 id 3。

最佳答案

使用 if_nametoindex () 函数。

unsigned int idx = if_nametoindex("eth0");
if (idx == 0) {
perror("if_nametoindex");
}

关于c++ - 如何以编程方式检索 eth0 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25485294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com