Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between IPAddress.Any and IPAddress.IPv6Any fields?

I tried the following code to make my code work in dual stack mode. Unfortunately, it's not opening port in the dual stack mode.

var listener = new TcpListener(IPAddress.Any, 2222);
listener.Server.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, 0);
listener.Start();

Later I realized that changing to var listener = new TcpListener(IPAddress.IPv6Any, 2222); would make it work for me. What exactly is the difference between

IPAddress.Any and IPAddress.IPv6Any fields?

The documentation on MSDN is a bit vague

like image 850
sarat Avatar asked Dec 02 '22 23:12

sarat


1 Answers

IPAddress.Any is for all IPv4 interfaces, IPAddress.IPv6Any is for all IPv6 interfaces.

IPAddress.Any is 0.0.0.0, IPAddress.IPv6Any is ::

If you just use IPv6Any without using SocketOptionName.IPv6Only then you can accept both IPv4 and IPv6 connections on the same socket.

like image 121
PhonicUK Avatar answered Dec 25 '22 04:12

PhonicUK