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."?
0.0 with netmask 0.0. 0.0 represents the default route. The same concept is also applied to IPv6, address 0:0:0:0:0:0:0:0 with netmask all 0s represents the default route. After applying IPv6 rule, this address is compressed to ::/0.
The name localhost normally resolves to the IPv4 loopback address 127.0. 0.1, and to the IPv6 loopback address ::1.
The best approach is to create an IPv6 server socket that can also accept IPv4 connections. To do so, create a regular IPv6 socket, turn off the socket option IPV6_V6ONLY , bind it to the "any" address, and start receiving. IPv4 addresses will be presented as IPv6 addresses, in the IPv4-mapped format.
The use of the “::” symbol is a special syntax that you can use to compress one or more group of zeros or to compress leading or trailing zeros in an address. The “::” can appear only once in an address. IPv6 uses a “/” notation which describes the no: of bits in netmask, similar to IPv4.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With