Quote:
Originally Posted by dwhitney67
Why don't you write a C program to experiment on your own as to what bind() will do in each of the scenarios you outlined above? While you are at it, read the man-page for bind.
|
I only saw the answer to the first one in the manpage. Also, experimentation gives you an idea of what to expect, but such anecdotes aren't a replacement for the facts, which I've learned the hard way numerous times.
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