bind function to assign an address to a socket. The
bind is in the header file sys/socket.h.
For examples of use, see Local Socket Example, or see Inet Example.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
bindfunction assigns an address to the socket socket. The addr and length arguments specify the address; the detailed format of the address depends on the namespace. The first part of the address is always the format designator, which specifies a namespace, and says that the address is in the format of that namespace.
The return value is
0on success and
-1on failure. The following
errnoerror conditions are defined for this function:
- The socket argument is not a valid file descriptor.
- The descriptor socket is not a socket.
- The specified address is not available on this machine.
- Some other socket is already using the specified address.
- The socket socket already has an address.
- You do not have permission to access the requested address. (In the Internet domain, only the super-user is allowed to specify a port number in the range 0 through
IPPORT_RESERVEDminus one; see Ports.)
Additional conditions may be possible depending on the particular namespace of the socket.