IPv6 区域索引和scope_id
区域索引与 sockaddr_in6 结构中的scope_id 有何关系?
平台之间的功能似乎有所不同,我很想知道它们之间的关系。例如,Windows 有一个 SCOPE_ID 结构(如以及一个 32 位值)。 Mac OSX 只有 32 位值。显然 32 位值是正确的选择,但它到底是如何布局的呢?难道前4位还是“级别”吗?网络字节顺序如何影响这一点?
我还假设,在 Windows 下,IP 地址中给出的区域索引(例如 FF80::1%1)直接转换为上述结构的底部 28 位。它如何在使用名称而不是数字的 Mac OSX 下工作(例如 FF80::1%en0)。我是否将其编码为 4 CC?同样,我似乎记得 linux 使用 4 个字符,这不可能适合 28 位。
那么有人可以向我解释一下这个混乱吗?当我完成后,我真的需要写一篇关于这一切的教程,因为网络上关于 ipv6 的信息很少。
编辑:scope_id 是网络字节顺序吗?我只是查看从recvfrom 返回的scope_id,它似乎是小端顺序......这不可能是正确的,不是吗?
How does the zone index relate to the scope_id in the sockaddr_in6 structure?
The functionality appears to differ between platforms and I'd love to know how they relate. Windows for example has a SCOPE_ID structure (as well as just a 32-bit value). Mac OSX only has a 32-bit value. Obviously the 32-bit value is the way to go but how exactly is it laid out? Is it still the top 4 bits are the "level"? How does network byte order affect this?
Also I assume that, under windows, the zone index given in the ip address (eg FF80::1%1) translates directly to the bottom 28 bits of the aforementioned structure. How does it work under Mac OSX that uses names rather than numbers (eg FF80::1%en0). Do I encode it as a four CC? Equally I seem to recall that linux uses 4 characters which couldn't possibly fit in 28-bits.
So can someone explain this mess to me? I really am going to need to write a tutorial on all this when I'm finished because there is precious little info about ipv6 around the net.
Edit: Is the scope_id in network byte order? I'm just looking at the scope_id returned from a recvfrom and it appears to be in little-endian order ... that can't be right can it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
区域和范围的索引相同并且经常互换,但术语本身不同。
范围的用法如“全局范围”、“本地范围”、“通用范围”,指的是特定 IPv6 地址的唯一性。每个接口都有一个本地范围,该范围对于直接 LAN 网段来说是唯一的,这对于本地设备的自动配置和发现很有用,例如您刚刚插入网络的打印机。全局范围 IPv6 地址可以由 DHCP 服务器提供。
区域是指定本地范围内特定的有效接口。
范围索引与接口索引不同,为了指定接口,我使用如下结构:
每个平台解释值的方式都是唯一的,Windows 根据域对接口枚举进行了多种重新解释。 Windows 实现的缺点是当您热插拔适配器时索引可能会发生变化。在 Unix 上,您通常会看到接口名称
%qe0
、%eth0
等,需要时可以将其解析为数字形式,例如if_nametoindex()
。 Windows Vista 添加了兼容的 API。只有本地作用域可以通过其地址前缀 fe80::/10 来识别。
Windows SCOPE_ID 显示了 IPv4 多播中也存在的设计,即分割地址的管理域。这完全是可选的并且经常被忽略。
The index of zone and scope are the same and frequently interchanged, however the terms themselves are different.
Scope is used as in "global scope", "local scope", "universal scope" and refer to how unique a particular IPv6 address is. Every interface has a local scope which is unique to the immediate LAN segment, which is say useful for automatic configuration and discovery of local devices, say a printer you just plugged into the network. Global scope IPv6 address may be provided by a DHCP server.
Zone is to specify a particular effective interface within the local scope.
The scope index is different from interface index such that to specify an interface I use a structure as follows:
Each platform is unique into how it interprets the value, with Windows having several re-interpretations of interface enumeration depending on domain. The downside with the Windows implementation is that the index can change when you hot swap adapters. On Unix you tend to see interface names
%qe0
,%eth0
, etc, that can be resolved to numeric form when required, e.g.if_nametoindex()
. Windows Vista adds a compatible API.Only the local scope is identifiable by it's address prefix fe80::/10.
The Windows SCOPE_ID shows over design that also exists in IPv4 multicast, i.e. splitting administration domains of addresses. It's all purely optional and frequently ignored.