In order for a server-side end-point to be useful, it has to be associated with something that client processes can find, such as IP address+port number, or the path of a named socket.
The bind function is used for this purpose. The first parameter is the FD returned by socket. This specifies which end-point to be associated with the external specifier.
The second parameter is “the address (as in a C address) of the address (as in where to find the end-point)”. The man page of bind (man 2 bind) describes that this parameter should be cast as an address to a struct sockaddr.
If the end-point is to be associated with a named socket, then struct sockaddr_un should be used as the actual address structure. Use man 7 unix to read the details of how to specify a named socket address.
In short, the sun_family field should have a value of AF_UNIX, where the sun_path field is a null-terminated path of the named socket.
Because the addr parameter of bind is cast to the address of the generic structure struct sockaddr, bind does not really know how big the structure is. This is why we need the third parameter, addrlen, to let bind know the exact size of addr. In order to use a named socket, this parameter should be sizeof{struct sockaddr_un.
The bind function returns 0 if it is successful. Otherwise, it returns -1.