gpt4 book ai didi

linux-kernel - 有关内核空间中网络接口(interface)的信息

转载 作者:行者123 更新时间:2023-12-02 01:30:15 24 4
gpt4 key购买 nike

我如何在内核空间中获取关于 eth0 的信息?我需要知道它是启用还是禁用,是否设置了 ipv6(当然还有 ipv6)。

最佳答案

您正在寻找struct net_device :

#include <linux/netdevice.h>

struct net_device *net_dev = __dev_get_by_name("eth0");

net_dev->flags; // IFF_UP will be set if an interface active (up)

获取IPv6地址需要获取struct inet6_dev从你的 net_device 中获取 IP 地址:

#include <net/addrconf.h>
#include <net/if_inet6.h>

struct inet6_dev *net_dev6 = in6_dev_get(net_device);

关于linux-kernel - 有关内核空间中网络接口(interface)的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34699823/

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