IPv6 套接字创建
我正在实施双堆栈模式来支持 IPv4 和 IPv6。 如果我创建一个 IPv6 套接字并侦听它,它也会接受来自 IPv4 套接字的连接吗?
I am implementing dual stack mode to support IPv4 and IPv6.
If I am creating a IPv6 socket and listening on it, will it accept the connection from IPv4 socket also ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,除非操作系统进行了其他配置,例如 Linux 中的
net.ipv6.bindv6only=1
,或者您设置了IPV6_V6ONLY
套接字选项。Yes, unless the operating system is configured otherwise, e.g.
net.ipv6.bindv6only=1
in Linux, or you set theIPV6_V6ONLY
socket option.仅当系统具有双栈实现时。大多数现代系统都支持,但旧版本的 Windows 和 OpenBSD 则不支持。但你不应该依赖这个。获取 IPV6_V6ONLY 套接字选项的值,如果它为零,则需要为 IPv4 打开第二个套接字。
当使用双栈套接字时,IPv4 地址表示为
::ffff:[IPv4 地址]
;例如::ffff:127.0.0.1
(这对应于::ffff:7f00:1
;为了便于阅读,它通常以点十进制表示法打印) 。Only if the system has a dual-stack implementation. Most modern systems do, but old versions of Windows and OpenBSD do not. You shouldn't rely on this though. Get the value of the IPV6_V6ONLY socket option and if it's zero you will need to open a second socket for IPv4.
When using a dual-stack socket IPv4 addresses are represented as
::ffff:[IPv4 address]
; for example::ffff:127.0.0.1
(this corresponds to::ffff:7f00:1
; it's just typically printed in dot-decimal notation for the sake of readability).根据微软 ,即使在双堆栈模式下,默认设置也是将 IPV6_V6ONLY 设置为 false - 但您可以通过setsockopt(2) 调用启用它。 FWIW,“旧版本”的 Windows(单堆栈)包括仍然广泛使用的 Windows XP(任何比 Vista 更旧的版本)。
因此,如果您使用的是 Windows,您应该尝试禁用 IPV6_V6ONLY 并查看是否成功。我不知道这对于其他单堆栈实现是否是一个好的答案。
According to Microsoft, the default even in dual stack mode is to have IPV6_V6ONLY set to false - but you can enable it through the setsockopt(2) call. FWIW, "Old versions" of Windows (single-stack) include the still-widely-used Windows XP (anything older than Vista).
So, if you're on Windows you should try and disable IPV6_V6ONLY and see if it succeeds. I don't know if that's a good answer for other single-stack implementations or not.