[Previous] [Contents] [Index] [Next]

bind()

Bind a name to a socket

Synopsis:

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

int bind( int s,
          const struct sockaddr * name,
          size_t namelen );

Library:

socket3r.lib, socket3s.lib

Description:

When a socket is created with socket(), it exists in a namespace (address family) but has no name assigned to it. The bind() function assigns a name to that unnamed socket.


Note: The bind() function assigns a local address. Use connect() to assign a remote address.

The rules used for binding names vary between communication domains.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EACCES
The requested address is protected, and the current user has inadequate permission to access it.
EADDRINUSE
The specified address is already in use.
EADDRNOTAVAIL
The specified address isn't available from the local machine.
EBADF
Invalid descriptor s.
EFAULT
The name parameter isn't in a valid part of the user address space.
EINVAL
The socket is already bound to an address.

Classification:

Standard Unix, POSIX 1003.1g (draft)

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

ICMP, IP, ROUTE, TCP, UDP, and UNIX protocols

connect(), getsockname(), listen(), socket()


[Previous] [Contents] [Index] [Next]