linux获取其他主机ipv6,linux – 如何获取IPv6主机的范围?

我对IPv6协议知之甚少,很抱歉,这个问题听起来很愚蠢.

当我检索网络中所有IPv6地址的列表时,我得到一个名为scope的字段,如下所示:

inet6 addr: 2001:470:1:82::11/64 Scope:Global

inet6 addr: 2001:470:1:82::10/64 Scope:Global

inet6 addr: 2001:470:1:82::13/64 Scope:Global

inet6 addr: fe80::21d:9ff:fe69:2c50/64 Scope:Link

inet6 addr: 2001:470:1:82::12/64 Scope:Global

inet6 addr: 2001:470:1:82::15/64 Scope:Global

inet6 addr: 2001:470:1:82::14/64 Scope:Global

inet6 addr: 2001:470:1:82::5/64 Scope:Global

inet6 addr: 2001:470:1:82::17/64 Scope:Global

inet6 addr: 2001:470:1:82::6/64 Scope:Global

inet6 addr: 2001:470:1:82::16/64 Scope:Global

inet6 addr: 2001:470:1:82::7/64 Scope:Global

inet6 addr: 2001:470:1:82::19/64 Scope:Global

inet6 addr: 2001:470:1:82::8/64 Scope:Global

inet6 addr: 2001:470:1:82::18/64 Scope:Global

inet6 addr: 2001:470:1:82::9/64 Scope:Global

inet6 addr: 2001:470:1:82::1b/64 Scope:Global

inet6 addr: 2001:470:1:82::a/64 Scope:Global

inet6 addr: 2001:470:1:82::1a/64 Scope:Global

inet6 addr: 2001:470:1:82::b/64 Scope:Global

inet6 addr: 2001:470:1:82::1d/64 Scope:Global

inet6 addr: 2001:470:1:82::c/64 Scope:Global

inet6 addr: 2001:470:1:82::1c/64 Scope:Global

inet6 addr: 2001:470:1:82::d/64 Scope:Global

inet6 addr: 2001:470:1:82::1f/64 Scope:Global

inet6 addr: 2001:470:1:82::e/64 Scope:Global

inet6 addr: 2001:470:1:82::1e/64 Scope:Global

inet6 addr: 2001:470:1:82::f/64 Scope:Global

inet6 addr: ::1/128 Scope:Host

在我的应用程序中,我需要获取范围为“链接”的那些地址.我可以使用系统调用ifconfig然后解析输出以提取相应的地址.但问题是,我正在使用getifaddrs()调用,它返回结构ifaddr的链表,给出如下:

struct ifaddrs {

struct ifaddrs *ifa_next; /* Next item in list */

char *ifa_name; /* Name of interface */

unsigned int ifa_flags; /* Flags from SIOCGIFFLAGS */

struct sockaddr *ifa_addr; /* Address of interface */

struct sockaddr *ifa_netmask; /* Netmask of interface */

union {

struct sockaddr *ifu_broadaddr;

/* Broadcast address of interface */

struct sockaddr *ifu_dstaddr;

/* Point-to-point destination address */

} ifa_ifu;

#define ifa_broadaddr ifa_ifu.ifu_broadaddr

#define ifa_dstaddr ifa_ifu.ifu_dstaddr

void *ifa_data; /* Address-specific data */

};

问题是:如何从此列表中获取具有“链接”范围的地址?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值