IPv6:侦听连接时,"::"是否等同于"0.0.0.0"? [英] IPv6: Is `::' equivalent to `0.0.0.0' when listening for connections?
问题描述
当我检查 IPGlobalProperties.GetActiveTcpListeners()
,我在0.0.0.0
和::
上看到了侦听器.
我相信在0.0.0.0
上的端口上侦听等同于在任何网络适配器上的端口上侦听,至少我对Windows套接字API的记忆如此.
对我来说,::
表示IPv6的等效含义,因此[::]:49156
上的侦听器将侦听所有IPv6网络适配器上的端口49156
,其中[::1]:1434
将是端口
这正确吗?
我假设IPv6侦听端点仅适用于IPv6适配器.也就是说,如果适配器仅具有IPv4地址,则[::]:49156
上的侦听器将不会接收与端口49156
的连接?
还有,没有人注意到GetActiveTcpListeners()
的MSDN文章错误地声明返回的对象在所有TCP状态中包括侦听器,除了 侦听状态"?
我相信在
0.0.0.0
上的端口上侦听等同于在任何网络适配器上的端口上侦听,至少我对Windows套接字API的记忆如此.
那是正确的. 0.0.0.0
定义为INADDR_ANY
,可用于侦听所有本地IPv4适配器.
对我来说,
::
表示IPv6的等效含义,因此:::49156
上的侦听器将侦听所有IPv6网络适配器上的端口49156
,其中::1:1434
将是端口1434仅IPv6回送适配器.
从聆听的角度来看,是的. ::
定义为INADDR6_ANY
,可用于侦听所有本地IPv6适配器. ::1
定义为INADDR6_LOOPBACK
.
我假设IPv6侦听端点仅适用于IPv6适配器.也就是说,如果适配器仅具有IPv4地址,则
:::49156
上的侦听器将不会接收与端口49156
的连接?
这取决于听众.仅IPv6的侦听器无法在IPv4适配器上侦听,也不能接受IPv4客户端.但是,双栈侦听器绑定到accept()
,WSAAccept()
和getpeername()
将IPv4地址报告为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."?
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.
That is correct. 0.0.0.0
is defined as INADDR_ANY
and can be used to listen on all local IPv4 adapters.
It also makes sense to me that
::
would mean the equivalent in IPv6 parlance so a listener on:::49156
would be listening to port49156
on all IPv6 network adapters where as::1:1434
would be port 1434 on only the IPv6 loopback adapter.
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
.
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
?
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"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!