问题
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."?
回答1:
I believe that listening on a port on
0.0.0.0is 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:::49156would be listening to port49156on all IPv6 network adapters where as::1:1434would 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
49156would 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.
回答2:
While your wording is misleading and in so far wrong, I think you mean to say the right thing: the unspecified address 0:0:0:0:0:0:0:0 a.k.a. :: means that the respective port isn't listening to a specific address, but to all of them - essentially the same what 0.0.0.0 in the IPv4 case says.
回答3:
The IPv6 address "::" is specifically unspecified, and is not a valid address, nor is it equivalent to the IPv4 address of "0.0.0.0". See RFC 3513, Internet Protocol Version 6 (IPv6) Addressing Architecture, section 2.5.2:
2.5.2 The Unspecified Address
The address 0:0:0:0:0:0:0:0 is called the unspecified address. It
must never be assigned to any node. It indicates the absence of an
address. One example of its use is in the Source Address field of
any IPv6 packets sent by an initializing host before it has learned
its own address.`
The unspecified address must not be used as the destination address
of IPv6 packets or in IPv6 Routing Headers. An IPv6 packet with a
source address of unspecified must never be forwarded by an IPv6
router.
来源:https://stackoverflow.com/questions/27480094/ipv6-is-equivalent-to-0-0-0-0-when-listening-for-connections