bind a name to a socket
s, const struct sockaddr
() assigns a name to an unnamed socket. When a
socket is created with
it exists in a name
space (address family) but has no name assigned.
() requests that name
assigned to the socket. namelen
indicates the amount of
space pointed to by name
, in bytes; the
member of name
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
The rules used in name binding vary between communication domains.
Consult the manual entries in section 4 for detailed information.
Upon successful completion, the value 0 is returned; otherwise the
value -1 is returned and the global variable
errno is set to indicate the error.
bind() function will fail if:
- s is not a valid descriptor.
- s is not a socket.
- The specified address is not available from the local machine.
- The specified address is already in use.
- The socket is already bound to an address, or
namelen is not a valid length for the supplied
- The family of the socket and that requested in
name->sa_family are not equivalent.
- Insufficient buffer space is available.
- The requested address is protected, and the current user has inadequate
permission to access it.
- The name parameter is not in a valid part of the
user address space.
The following errors are specific to binding names in the
- A component of the path prefix is not a directory.
- A component of a pathname exceeded
characters, or an entire pathname (including the terminating NUL) exceeded
- A prefix component of the path name does not exist.
- Too many symbolic links were encountered in translating the pathname.
- An I/O error occurred while making the directory entry or allocating the
- The name would reside on a read-only file system.
- An empty pathname was specified.
bind() function conforms to IEEE
Std 1003.1-2008 (“POSIX.1”).
bind() system call first appeared in