检测临时IPv6地址跨平台 [英] detect temporary ipv6 address crossplatform

查看:205
本文介绍了检测临时IPv6地址跨平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检测是否一个​​地址是临时的IPv6地址,我用getifaddrs获得地址的列表,但不知道如何从那里得到这些信息。如果可能的话,我想,要为Linux,OSX,Solaris和Windows工作。

I want to detect if an address is temporary ipv6 address, i using getifaddrs to get the list of addresses but don't know how to get that info from there. And if possible i want that to work for linux, osx, solaris and windows.

我看来,在Linux的IFA_F_TEMPORARY在设置inet6_ifaddr-> ifa_flags,但不知道如果我怎样才能从由getifaddrs返回的ifaddrs。

I have seems that in Linux IFA_F_TEMPORARY is set in inet6_ifaddr->ifa_flags, but not sure if how can i get that from the ifaddrs returned by getifaddrs.

看来,在OSX我OCTL需要SIOCSIFINFO_FLAGS,我也没有有关Solaris或Windows想法。

Seems that on OSX i need octl with SIOCSIFINFO_FLAGS, and i have no idea about Solaris or Windows.

有任何身体样本code,可以做到这一点。

has any body a sample code that could do that.

推荐答案

更新(2016年8月3日):搜索和关闭在过去的几个月后这个问题(因为我需要这个其实是我回答)。我相信我已经找到了Windows为中心的答案。我只测试了这个在Windows 10,所以我不知道旧的版本。但这种API不应该改变,如果有人想验证我: - )

Updated (Aug 3, 2016): After searching on and off for the past couple months on this question (because I'm actually in need of this answer myself). I believe I have found the Windows-centric answer. I've only tested this on Windows 10, so I don't know about older versions. But this API shouldn't have changed if someone wants to verify it for me :-)

所有的 _IP_ADAPTER_UNICAST_ADDRESS 结构有地址preFIX和后缀的枚举。现在我已经懒得去看看他们,他们是解决这一问题的整个密钥!

All _IP_ADAPTER_UNICAST_ADDRESS structures have an enumeration for the address prefix and suffix. I've now bothered to look at them and they are the entire key to solving this issue!

什么是临时IPv6地址....这是一个字尾的地址!因此,对于所有IPv6在地址IP_ADAPTER_UNICAST_ADDRESS看在 IP_SUFFIX_ORIGIN 看它是否 IpSuffixOriginRandom 。而已。

What is a Temporary IPv6 address....it's an address with a RANDOM SUFFIX! So for all IPv6 addresses in a IP_ADAPTER_UNICAST_ADDRESS look at the IP_SUFFIX_ORIGIN see if it is IpSuffixOriginRandom. Thats...it.

我真的很震惊还是怎么一点没有关于这一主题的在线,这将是一个巨大的问题在几年网络的应用程序开发人员,如果没有人知道如何解决这个问题的服务器端应用程序(甚至是那些运行在消费者PC)

I'm really still shocked at how little there on this topic online and this will be a huge issue in a few years for network application developers if no one knows how to solve this issue for server-side applications (even ones running on consumer PCs)

您听到的答案在这里第一次!

You heard the answer here first!!!

(原来的答案):我一直在寻找一个跨平台应用程序这个确切的题目为好。我想我已经找到了一的方式在Windows过滤IPv6临时地址。基本上RFC 4941声称临时地址必须:

(Original Answer): I've been looking at this exact topic for a cross-platform application as well. I think I've found "a" way to filter IPv6 temporary addresses in Windows. Basically RFC 4941 claims temporary addresses must:


  1. 有一个有效寿命低于公共地址

  2. 有一个preferred寿命低​​于公共地址

所以对于C ++,使用函数像GetAdaptersAddresses时,你可以看在PIP_ADAPTER_ADDRESSES结构的_IP_ADAPTER_UNICAST_ADDRESS结构和评估ValidLifetime和preferredLifetime成员。过滤地址类型(如果你需要知道本地链路VS公共)后,你可以保持最大的一生的流水帐。 (每个适配器)最大续航时间应该是公有地址!

So for C++, when using a function like GetAdaptersAddresses you can look in the PIP_ADAPTER_ADDRESSES struct for the _IP_ADAPTER_UNICAST_ADDRESS struct and evaluate the ValidLifetime and PreferredLifetime members. After filtering for address type (if you need to know Local-Link vs Public) you can keep a running tally of the largest lifetime. The largest life time (per adapter) should be the public address!

要看到地址生存方式快速运行Windows终端命令:netsh接口的IPv6地址显示

To see the address lifetime info quickly run the Windows terminal command: netsh interface ipv6 show address

您可以看到所有临时地址比默认SLAAC寿命小得多。

You can see all temporary addresses are much smaller than the defaulted SLAAC lifetimes.

我与这个假设工作即日起至测试证明并非如此。所有临时地址基于公众,因此不能出去住吧。

I'm working with this assumption for now until testing proves otherwise. All Temporary addresses are based on the public and so cannot out live it.

希望这有助于

这篇关于检测临时IPv6地址跨平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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