Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPv6: Is `::' equivalent to `0.0.0.0' when listening for connections?

Tags:

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."?

like image 218
Xharlie Avatar asked Dec 15 '14 08:12

Xharlie


People also ask

What is the 0:0:0:0 0 equivalent for IPv6?

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.

What is the equivalent of 127.0 0.1 in IPv6?

The name localhost normally resolves to the IPv4 loopback address 127.0. 0.1, and to the IPv6 loopback address ::1.

How can I listen on IPv4 and IPv6?

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.

What is ::: in IPv6?

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.


2 Answers

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 port 49156 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.

like image 160
Remy Lebeau Avatar answered Sep 18 '22 13:09

Remy Lebeau


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.

like image 23
glglgl Avatar answered Sep 21 '22 13:09

glglgl