1BIND(P) POSIX Programmer's Manual BIND(P)
2
3
4
6 bind - bind a name to a socket
7
9 #include <sys/socket.h>
10
11 int bind(int socket, const struct sockaddr *address,
12 socklen_t address_len);
13
14
16 The bind() function shall assign a local socket address address to a
17 socket identified by descriptor socket that has no local socket address
18 assigned. Sockets created with the socket() function are initially
19 unnamed; they are identified only by their address family.
20
21 The bind() function takes the following arguments:
22
23 socket Specifies the file descriptor of the socket to be bound.
24
25 address
26 Points to a sockaddr structure containing the address to be
27 bound to the socket. The length and format of the address depend
28 on the address family of the socket.
29
30 address_len
31 Specifies the length of the sockaddr structure pointed to by the
32 address argument.
33
34
35 The socket specified by socket may require the process to have appro‐
36 priate privileges to use the bind() function.
37
39 Upon successful completion, bind() shall return 0; otherwise, -1 shall
40 be returned and errno set to indicate the error.
41
43 The bind() function shall fail if:
44
45 EADDRINUSE
46 The specified address is already in use.
47
48 EADDRNOTAVAIL
49 The specified address is not available from the local machine.
50
51 EAFNOSUPPORT
52 The specified address is not a valid address for the address
53 family of the specified socket.
54
55 EBADF The socket argument is not a valid file descriptor.
56
57 EINVAL The socket is already bound to an address, and the protocol does
58 not support binding to a new address; or the socket has been
59 shut down.
60
61 ENOTSOCK
62 The socket argument does not refer to a socket.
63
64 EOPNOTSUPP
65 The socket type of the specified socket does not support binding
66 to an address.
67
68
69 If the address family of the socket is AF_UNIX, then bind() shall fail
70 if:
71
72 EACCES A component of the path prefix denies search permission, or the
73 requested name requires writing in a directory with a mode that
74 denies write permission.
75
76 EDESTADDRREQ or EISDIR
77 The address argument is a null pointer.
78
79 EIO An I/O error occurred.
80
81 ELOOP A loop exists in symbolic links encountered during resolution of
82 the pathname in address.
83
84 ENAMETOOLONG
85 A component of a pathname exceeded {NAME_MAX} characters, or an
86 entire pathname exceeded {PATH_MAX} characters.
87
88 ENOENT A component of the pathname does not name an existing file or
89 the pathname is an empty string.
90
91 ENOTDIR
92 A component of the path prefix of the pathname in address is not
93 a directory.
94
95 EROFS The name would reside on a read-only file system.
96
97
98 The bind() function may fail if:
99
100 EACCES The specified address is protected and the current user does not
101 have permission to bind to it.
102
103 EINVAL The address_len argument is not a valid length for the address
104 family.
105
106 EISCONN
107 The socket is already connected.
108
109 ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during
110 resolution of the pathname in address.
111
112 ENAMETOOLONG
113 Pathname resolution of a symbolic link produced an intermediate
114 result whose length exceeds {PATH_MAX}.
115
116 ENOBUFS
117 Insufficient resources were available to complete the call.
118
119
120 The following sections are informative.
121
123 None.
124
126 An application program can retrieve the assigned socket name with the
127 getsockname() function.
128
130 None.
131
133 None.
134
136 connect() , getsockname() , listen() , socket() , the Base Definitions
137 volume of IEEE Std 1003.1-2001, <sys/socket.h>
138
140 Portions of this text are reprinted and reproduced in electronic form
141 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
142 -- Portable Operating System Interface (POSIX), The Open Group Base
143 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
144 Electrical and Electronics Engineers, Inc and The Open Group. In the
145 event of any discrepancy between this version and the original IEEE and
146 The Open Group Standard, the original IEEE and The Open Group Standard
147 is the referee document. The original Standard can be obtained online
148 at http://www.opengroup.org/unix/online.html .
149
150
151
152IEEE/The Open Group 2003 BIND(P)