What does socket bind 0.0.0.0:myport mean?
First I use ifconfig to see all my network interfaces in my server A as below.
Code:
eth0 Link encap:Ethernet HWaddr 00:50:56:9C:57:65 1、What will bind do if I give bind function none of the ip address listed with ifconfig? 2、What will bind do if I give bind function the address 0.0.0.0? 3、What will bind do if I give bind function the address 127.0.0.1? Thanks in advance if you can unlock my mind. |
Quote:
Oh sorry... you wanted the quick answer: 1. Fail. 2. Success. 3. Success. |
Quote:
I can experiment out the answer by writing the test code. Actually what I don't understand is the reason and the internal scenario. |
Quote:
If you use the INADDR_ANY macro when creating a socket, that expands to the netlong value of 0.0.0.0. This means that the socket will be bound to all available IP addresses on the machine, which is convenient but sometimes bad. If you use the INADDR_LOOPBACK macro, that expands to the netlong value of 127.0.0.1, which is the default IP address of the loopback interface. You should use those macros whenever appropriate, rather than the dot-decimal notation. Kevin Barry |
All times are GMT -5. The time now is 09:00 PM. |