What does bind() do, exactly?
I know, you need to bind() explicitly if you want to receive anything (i.e. incoming connection requests, or connectionless datagrams), so that the sender can actually know where to send packets; and the sender need not bind to a specific port (or explicitly bind at all, for connection-oriented sockets), since its port doesn't need to be pre-known and it's an unnecessary risk since the port may already be in use.
So I have a fair idea of what the port is for, in the sockaddr_in struct - something along the lines of a PO box or apt. number. However, what I don't understand is what the IP address is for. In all examples I've seen, it is simply set to INADDR_ANY, with the explanation being "any address is fine". What exactly does this address signify? For some time, I was thought that it was the range of addresses that you are interested in receiving packets from; but that doesn't make sense, since you can only specify one address or all addresses. After this, I had the impression that it has something to do with the local computer's hardware, but I am unsure exactly what. Can someone explain what it is used for, and possibly give an example of a situation in which it would be set to something other than INADDR_ANY? Thanks.