IPv6和IPv4的套接字侦听器 [英] Socket listener for IPv6 and IPv4

查看:444
本文介绍了IPv6和IPv4的套接字侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用流行的教程移植了一个支持IPv6的应用程序。我决定对这两种协议只使用一个套接字侦听器。现在我意识到我必须正确设置 IPV6_V6ONLY (它只工作在我的x86 linux开箱,但不是在我的ARM)。

I ported an application to support IPv6, using popular tutorials. I decided to use only one socket listener for both protocols. Now I realized I have to set IPV6_V6ONLY properly (it's only working on my x86 linux out of the box, but not on my ARM).

这是真的吗?有人说 IPV6_V6ONLY 不应该使用(显然它已经过时,因为IPv4映射通过线),有人说使用一个套接字的两个协议都很好。

Is this really the way to go? Some say IPV6_V6ONLY shouldn't be used (apparently it's outdated, because of IPv4 mapping over the wire), some say using one socket for both protocols is fine.

所以,我很困惑。这个问题的当前状态是什么?

So, I'm confused. What is the current state about this problem? Did I misunderstand the problem?

推荐答案

您应该始终明确绑定两个套接字,IPv6套接字绑定 IPV6_V6ONLY

You should always bind both sockets explicitly, with the IPv6 socket bound with IPV6_V6ONLY.

为什么?跨平台兼容性。

Why? Cross-platform compatibility.

默认情况下,Windows需要在IPv4和IPv6上显式绑定。仅绑定到IPv6不会隐式绑定到IPv4。

Windows by default requires that you explicitly bind on IPv4 and IPv6. Binding only to IPv6 will not implicitly bind to IPv4 as well.

默认情况下,当您在IPv6上绑定时,Linux默认会隐式绑定到IPv4,只有当 net.ipv6.bindv6only sysctl设置为 0 。像Debian这样的分发将此默认值更改为 1 ,打破了你的假设。

Linux by default will implicitly bind to IPv4 as well when you bind on IPv6, only if the net.ipv6.bindv6only sysctl is set to 0. Distributions such as Debian change this default to 1, breaking your assumption.

我不记得什么Mac OS X在这里(有人在评论中的啁啾吗?),但要点是显式绑定到这两个协议没有任何惊喜。

I can't remember what Mac OS X does here (someone chirp in the comments please?), but the point is that explicitly binding to both protocols leaves no surprises.

这篇关于IPv6和IPv4的套接字侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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