The bind() function allows to specify the source address for datagrams sent to the socket. In most cases, though, this can be left to the operating system. A common practice for IPv4 is to use bind() in the following way:

The symbolic constant INADDR_ANY signals the operating system to select an appropriate source address, in much the same way as zero port number on the previous line asks for arbitrary free port number.
Due to the fact that in_addr is nothing but a scalar value written in a cryptic way, INADDR_ANY
constant can be used in assignment expressions as we just saw in the example. This is no more true for IPv6, since in6_addr type contains an array. For this purpose, the global variable in6addr_any is defined in the header file <netinet/in.h>. It can be used in a similar way as INADDR_ANY

A similar issue arises in the case of the loopback interface whose address can be used as either source or destination address. Again, for IPv4 we have the symbolic constant INADDR_LOOPBACK corresponding to 127.0.0.1, whereas for IPv6 we have to choose one of the two alternatives:
• global variable in6addr_loopback
• symbolic constant IN6ADDR_ANY_INIT useful only for variable initialisation.
