1BIND(3P)                   POSIX Programmer's Manual                  BIND(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       bind - bind a name to a socket
13

SYNOPSIS

15       #include <sys/socket.h>
16
17       int bind(int socket, const struct sockaddr *address,
18              socklen_t address_len);
19
20

DESCRIPTION

22       The bind() function shall assign a local socket address  address  to  a
23       socket identified by descriptor socket that has no local socket address
24       assigned. Sockets created with  the  socket()  function  are  initially
25       unnamed; they are identified only by their address family.
26
27       The bind() function takes the following arguments:
28
29       socket Specifies the file descriptor of the socket to be bound.
30
31       address
32              Points  to  a  sockaddr  structure  containing the address to be
33              bound to the socket. The length and format of the address depend
34              on the address family of the socket.
35
36       address_len
37              Specifies the length of the sockaddr structure pointed to by the
38              address argument.
39
40
41       The socket specified by socket may require the process to  have  appro‐
42       priate privileges to use the bind() function.
43

RETURN VALUE

45       Upon  successful completion, bind() shall return 0; otherwise, -1 shall
46       be returned and errno set to indicate the error.
47

ERRORS

49       The bind() function shall fail if:
50
51       EADDRINUSE
52              The specified address is already in use.
53
54       EADDRNOTAVAIL
55              The specified address is not available from the local machine.
56
57       EAFNOSUPPORT
58              The specified address is not a valid  address  for  the  address
59              family of the specified socket.
60
61       EBADF  The socket argument is not a valid file descriptor.
62
63       EINVAL The socket is already bound to an address, and the protocol does
64              not support binding to a new address; or  the  socket  has  been
65              shut down.
66
67       ENOTSOCK
68              The socket argument does not refer to a socket.
69
70       EOPNOTSUPP
71              The socket type of the specified socket does not support binding
72              to an address.
73
74
75       If the address family of the socket is AF_UNIX, then bind() shall  fail
76       if:
77
78       EACCES A  component of the path prefix denies search permission, or the
79              requested name requires writing in a directory with a mode  that
80              denies write permission.
81
82       EDESTADDRREQ or EISDIR
83              The address argument is a null pointer.
84
85       EIO    An I/O error occurred.
86
87       ELOOP  A loop exists in symbolic links encountered during resolution of
88              the pathname in address.
89
90       ENAMETOOLONG
91              A component of a pathname exceeded {NAME_MAX} characters, or  an
92              entire pathname exceeded {PATH_MAX} characters.
93
94       ENOENT A  component  of  the pathname does not name an existing file or
95              the pathname is an empty string.
96
97       ENOTDIR
98              A component of the path prefix of the pathname in address is not
99              a directory.
100
101       EROFS  The name would reside on a read-only file system.
102
103
104       The bind() function may fail if:
105
106       EACCES The specified address is protected and the current user does not
107              have permission to bind to it.
108
109       EINVAL The address_len argument is not a valid length for  the  address
110              family.
111
112       EISCONN
113              The socket is already connected.
114
115       ELOOP  More  than  {SYMLOOP_MAX} symbolic links were encountered during
116              resolution of the pathname in address.
117
118       ENAMETOOLONG
119              Pathname resolution of a symbolic link produced an  intermediate
120              result whose length exceeds {PATH_MAX}.
121
122       ENOBUFS
123              Insufficient resources were available to complete the call.
124
125
126       The following sections are informative.
127

EXAMPLES

129       None.
130

APPLICATION USAGE

132       An  application  program can retrieve the assigned socket name with the
133       getsockname() function.
134

RATIONALE

136       None.
137

FUTURE DIRECTIONS

139       None.
140

SEE ALSO

142       connect(), getsockname(), listen(), socket(), the Base Definitions vol‐
143       ume of IEEE Std 1003.1-2001, <sys/socket.h>
144
146       Portions  of  this text are reprinted and reproduced in electronic form
147       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
148       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
149       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
150       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
151       event of any discrepancy between this version and the original IEEE and
152       The  Open Group Standard, the original IEEE and The Open Group Standard
153       is the referee document. The original Standard can be  obtained  online
154       at http://www.opengroup.org/unix/online.html .
155
156
157
158IEEE/The Open Group                  2003                             BIND(3P)
Impressum