IPv6和IPv4的套接字侦听器

编程入门 行业动态 更新时间:2024-10-28 14:35:23
本文介绍了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的套接字侦听器

本文发布于:2023-10-24 08:17:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523419.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:侦听器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!