Associates local address information with a socket.
#include <sys/socket.h> int bind ( int s, const struct sockaddr *addr, size_t len);
(IN) Specifies the socket file handle to which address information is to be assigned.
(IN) Points to the location for the address that is assigned to an unbound socket. For IPv4, addr should point to a sockaddr structure; for IPv6, to a sockaddr_in6 structure.
(IN) Specifies the amount of space (in bytes) pointed to by addr.
If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following:
When a socket is created, the socket exists in an addr space (address family) but has no address assigned. The bind function requests that an address be assigned to the socket. Once addr is bound to a socket, another socket can establish communication by referring to that address.
If you want to specify the local address, pass INADDR_ANY (zero) as the IP address to addr. The protocol code then assigns the local address. You can still specify the TCP port in the sin_port or sin6_port field.