BIND(2)

NAME
bind - bind a name to a socket

SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>

int bind(int sockfd, struct sockaddr *my_addr, int addrlen);

DESCRIPTION
bind gives the socket, sockfd, the local address my_addr. my_addr is addrlen bytes long. Traditionally, this is called "assigning a name to a socket" (when a socket is created with socket(2), it exists in a name space (address family) but has no name assigned.)

NOTES
Binding a name in the UNIX domain creates a socket in the file system that must be deleted by the caller when it is no longer needed (using unlink(2)). The rules used in name binding vary between communication domains. Consult the manual entries in section 4 for detailed information.

RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is set appropriately.

ERRORS

EBADF
    sockfd is not a valid descriptor.

EINVAL
    The socket is already bound to an address. This may change in the future: see linux/unix/sock.c for details.

EACCES
    The address is protected, and the user is not the super-user.

The following errors are specific to UNIX domain (AF_UNIX) sockets:

EINVAL
    The addr_len was wrong, or the socket was not in the AF_UNIX family.

EROFS
    The socket inode would reside on a read-only file system.

EFAULT
    my_addr points outside your accessible address space.

ENAMETOOLONG
    my_addr is too long.

ENOENT
    The file does not exist.

ENOMEM
    Insufficient kernel memory was available.

ENOTDIR
    A component of the path prefix is not a directory.

EACCES
    Search permission is denied on a component of the path prefix.

ELOOP
    my_addr contains a circular reference (i.e., via a symbolic link)

HISTORY
The bind function call appeared in BSD 4.2.

SEE ALSO
accept(2), connect(2), listen(2), socket(2), getsockname(2)