我应该在与 IPv4 不同的端口上侦听 IPv6 连接吗?
我有一个程序可以监听连接并处理它们。我知道许多网络堆栈支持通过同一套接字/端口接受 IPv4 和 IPv6 连接,但我也听说 Windows XP 不是其中之一。为了让相同的代码在所有平台上运行良好,我是否应该在单独的端口上侦听 IPv6 连接?
I have a program that listens for connections and handles them. I am aware that many networking stacks support accepting IPv4 and IPv6 connections over the same socket/port, but I've also heard that Windows XP isn't one of those. In the interest of having the same code run well on all platforms, should I just listen for IPv6 connections on a separate port?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Windows XP SP2+ 实现了
双栈IP
架构。这意味着您可以有两个绑定到相同端口号的套接字(一个用于 AF_INET,另一个用于 AF_INET6 系列)。这工作得很好。注意:如果您的目的是使用单个套接字来处理 IPv4 和 IPv6 连接,那么您依赖于 Windows Vista 及更高版本中实现的所谓的
双 IP 层堆栈
架构(在这种情况下,您必须禁用该套接字上的IPV6_V6ONLY
选项)。请参阅 Microsoft IP 版本 6 的目标
另请参阅 IPv6 过渡的应用方面 (RFC 4038) 。
PS:BiggsSTRC 目前接受的答案通常不准确,如相应评论中所述。但是,如果您同意使用两个端口号 - 那么这个答案仍然很有意义。
PS2:我使用了链接文章中的术语。不确定是否有任何其他平台在
双栈
和双层
术语之间使用这种分离。Windows XP SP2+ implements
dual-stack IP
architecture. That means that you can have two sockets (one for AF_INET and another one for AF_INET6 family) which are bound to the same port number. This works quite fine.Note: if your intention was to have a single socket to handle both IPv4 and IPv6 connections then you depend on the so called
dual IP layer stack
architecture implemented in Windows Vista and later (in this case you'll have to disableIPV6_V6ONLY
options on that socket).Refer to Microsoft's Objectives for IP Version 6
Check also general recomendations in Application Aspects of IPv6 Transition (RFC 4038) .
PS: currently accepted answer by BiggsTRC is generally inaccurate as explained in the corresponding comments. However, if you are Ok with using two port numbers - then that answer still makes perfect sense.
PS2: I used terminology from the linked article. Not sure if any other platform uses this kind of separation between
dual-stack
anddual-layer
terms.如果您希望与 XP 平台兼容,最简单的答案是监听两个单独的端口。如果您想变得复杂,您可能可以进行操作系统检测并在运行时确定端口之类的东西,但这似乎过于复杂,因为只需两个端口即可解决问题。
以下是有关 IPv6 和 XP 的详细信息的链接:
http://msdn.microsoft.com/en-us/library/bb513665(v=vs.85).aspx
If you are looking to be compatible with the XP platform, the simplest answer is to listen on two separate ports. If you want to get complicated, you could probably do OS detection and determine ports at runtime or something but that seems overly complicated when simply having two ports will solve the issue.
Here is a link with more information on IPv6 and XP:
http://msdn.microsoft.com/en-us/library/bb513665(v=vs.85).aspx