A socket created with s=socket() initially has no name. The socket must therefore be assigned a name, i.e. a local address, according to its address family. Processes can only address the socket and receive messages over it after this is done. You bind a name to the socket, i.e. you assign the socket a local address, with the bind() function.
You call bind() as follows:
bind(s, name, namelen);
The structure of the name name, which is assigned to socket s, differs according to the address family (AF_INET, AF_INET6 or AF_UNIX).
In the communications domain AF_INET, name comprises a 4-byte IPv4 address and a port number. name is passed in a variable of the type struct sockaddr_in (see "sockaddr_in address structure of the AF_INET address family ").
In the communications domain AF_INET6, name comprises a 16-byte IPv6 address and a port number. name is passed in a variable of the type struct sockaddr_in6 (see "sockaddr_in6 address structure of the AF_INET6 address family ").
namelen contains the length of the data structure that describes the name.