本文介绍了IPv6:侦听连接时,"::"是否等同于"0.0.0.0"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我检查 IPGlobalProperties.GetActiveTcpListeners() ,我在0.0.0.0::上看到了侦听器.

我相信在0.0.0.0上的端口上侦听等同于在任何网络适配器上的端口上侦听,至少我对Windows套接字API的记忆如此.

对我来说,::表示IPv6的等效含义,因此[::]:49156上的侦听器将侦听所有IPv6网络适配器上的端口49156,其中[::1]:1434将是端口仅在IPv6回送适配器上.

这正确吗?

我假设IPv6侦听端点仅适用于IPv6适配器.也就是说,如果适配器仅具有IPv4地址,则[::]:49156上的侦听器将不会接收与端口49156的连接?

还有,没有人注意到GetActiveTcpListeners()的MSDN文章错误地声明返回的对象在所有TCP状态中包括侦听器,除了 侦听状态"?

解决方案

那是正确的. 0.0.0.0定义为INADDR_ANY,可用于侦听所有本地IPv4适配器.

从聆听的角度来看,是的. ::定义为INADDR6_ANY,可用于侦听所有本地IPv6适配器. ::1定义为INADDR6_LOOPBACK.

这取决于听众.仅IPv6的侦听器无法在IPv4适配器上侦听,也不能接受IPv4客户端.但是,双栈侦听器绑定到可以绑定到IPv4和IPv6适配器并接受IPv4和IPv6客户端,其中accept()WSAAccept()getpeername()将IPv4地址报告为 IPv4映射的IPv6地址.

When I examine the output of IPGlobalProperties.GetActiveTcpListeners(), I see listeners on 0.0.0.0 as well as ::.

I believe that listening on a port on 0.0.0.0 is equivalent to listening on a port on any network adapter, at least my memory of the Windows socket API says that this is so.

It also makes sense to me that :: would mean the equivalent in IPv6 parlance so a listener on [::]:49156 would be listening to port 49156 on all IPv6 network adapters where as [::1]:1434 would be port 1434 on only the IPv6 loopback adapter.

Is this correct?

I assume that IPv6 listen end-points only apply to IPv6 adapters. That is, if an adapter only had an IPv4 address, connections to it port 49156 would not be received by a listener on [::]:49156?

Also, has anyone noticed that the MSDN article for GetActiveTcpListeners() incorrectly declares that the returned objects "include listeners in all TCP states except the Listen state."?

解决方案

That is correct. 0.0.0.0 is defined as INADDR_ANY and can be used to listen on all local IPv4 adapters.

From the perspective of listening, yes. :: is defined as INADDR6_ANY and can be used to listen on all local IPv6 adapters. ::1 is defined as INADDR6_LOOPBACK.

That depends on the listener. An IPv6-only listener cannot listen on an IPv4 adapter and cannot accept IPv4 clients. However, a dual-stack listener bound to INADDR6_ANY can bind to IPv4 and IPv6 adapters and accept both IPv4 and IPv6 clients, where IPv4 addresses are reported by accept(), WSAAccept(), and getpeername() as IPv4-mapped IPv6 addresses.

这篇关于IPv6:侦听连接时,"::"是否等同于"0.0.0.0"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:54
查看更多