bind

Binds a name to a socket.

Format

#include  <socket.h>

int bind  (int s, struct sockaddr *name, int
          namelen);
Routine Variants This socket routine has a variant named __bsd44_bind. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD-compatible semantics. See Section A.7 for more information.

Arguments

s
A socket descriptor that has been created with socket.
name
Address of a structure used to assign a name to the socket in the format specific to the family (AF_INET) socket address. See <socket.h> for a description of the sockaddr structure.
namelen
The size, in bytes, of the structure pointed to by name.

Description

This routine assigns a name to an unnamed socket. When a socket is created with socket it exists in a name space (address family) but has no name assigned. The bind routine requests that a name be assigned to the socket.

See also connect, getsockname, listen, and socket in this appendix.

Return Values
Indicates success. 
-1  Indicates an error; errno is set to one of the following values:

  • EBADF - The socket descriptor is invalid.

  • ENOTSOCK - The socket descriptor references a file, not a socket.

  • EADDRNOTAVAIL - specified address is not available from the local machine.

  • EADDRINUSE - The specified Internet address and ports are already in use.

  • EINVAL - The socket is already bound to an address.

  • EACCESS - The requested address is protected, and the current user has inadequate permission to access it.

  • EFAULT - The name parameter is not a valid part of the user address space.
 


Previous Page | Next Page | Table of Contents | Index