What is IP address '::1'?

孤人 提交于 2019-11-26 08:09:02

问题


I was playing with sockets on local machine with no network connection. See below:

IPAddress address = IPAddress.Any; // doesn\'t work
IPAddress address = IPAddress.Parse(\"::1\"); // works

So what is exactly ::1 IP address ? Is it the default available IP address or it\'s the loopback address ? what happens to above code (working line) on a machine with dedicated IP address and network connection ?

EDIT:

exact code is used to bind a specific IP address to socket. Here it is:

ServicePoint sp = ServicePointManager.FindServicePoint(uri);
sp.BindIPEndPointDelegate = new BindIPEndPoint(Bind);
// here\'s the bind delegate:
private IPEndPoint Bind(ServicePoint sp, IPEndPoint ep, int retryCount)
{
   return new IPEndPoint(IPAddress.Parse(\"::1\"), 0);
}

回答1:


::1 is the loopback address in IPv6. Think of it as the IPv6 version of 127.0.0.1.

See http://en.wikipedia.org/wiki/Localhost




回答2:


Just to add little more info to it, in IPv6 loopback address is represented as 127 zeroes followed by a 1 i.e (0000... 127 times..1). It's representation should have been like this -> 0000:0000:0000:0000:0000:0000:0000:0001 but we have some short form representation for this. If there are all zeroes in a single block you can replace it by single 0. So it becomes -> 0:0:0:0:0:0:0:0001. Again we can see that we have runs of zeroes, they can be eliminated and we get -> ::0001 -> ::1 .



来源:https://stackoverflow.com/questions/4611418/what-is-ip-address-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!