]>
Commit | Line | Data |
---|---|---|
9bccf70c A |
1 | .\" $NetBSD: bind.2,v 1.8 1995/10/12 15:40:46 jtc Exp $ |
2 | .\" | |
3 | .\" Copyright (c) 1983, 1993 | |
4 | .\" The Regents of the University of California. All rights reserved. | |
5 | .\" | |
6 | .\" Redistribution and use in source and binary forms, with or without | |
7 | .\" modification, are permitted provided that the following conditions | |
8 | .\" are met: | |
9 | .\" 1. Redistributions of source code must retain the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer. | |
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer in the | |
13 | .\" documentation and/or other materials provided with the distribution. | |
14 | .\" 3. All advertising materials mentioning features or use of this software | |
15 | .\" must display the following acknowledgement: | |
16 | .\" This product includes software developed by the University of | |
17 | .\" California, Berkeley and its contributors. | |
18 | .\" 4. Neither the name of the University nor the names of its contributors | |
19 | .\" may be used to endorse or promote products derived from this software | |
20 | .\" without specific prior written permission. | |
21 | .\" | |
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | .\" SUCH DAMAGE. | |
33 | .\" | |
34 | .\" @(#)bind.2 8.1 (Berkeley) 6/4/93 | |
35 | .\" | |
36 | .Dd June 4, 1993 | |
37 | .Dt BIND 2 | |
38 | .Os BSD 4.2 | |
39 | .Sh NAME | |
40 | .Nm bind | |
41 | .Nd bind a name to a socket | |
42 | .Sh SYNOPSIS | |
9bccf70c A |
43 | .Fd #include <sys/socket.h> |
44 | .Ft int | |
2d21ac55 A |
45 | .Fo bind |
46 | .Fa "int socket" | |
47 | .Fa "const struct sockaddr *address" | |
48 | .Fa "socklen_t address_len" | |
49 | .Fc | |
9bccf70c A |
50 | .Sh DESCRIPTION |
51 | .Fn Bind | |
52 | assigns a name to an unnamed socket. | |
53 | When a socket is created | |
54 | with | |
55 | .Xr socket 2 | |
56 | it exists in a name space (address family) | |
57 | but has no name assigned. | |
58 | .Fn Bind | |
59 | requests that | |
2d21ac55 | 60 | .Fa address |
9bccf70c A |
61 | be assigned to the socket. |
62 | .Sh NOTES | |
63 | Binding a name in the UNIX domain creates a socket in the file | |
64 | system that must be deleted by the caller when it is no longer | |
65 | needed (using | |
66 | .Xr unlink 2 ) . | |
67 | .Pp | |
68 | The rules used in name binding vary between communication domains. | |
69 | Consult the manual entries in section 4 for detailed information. | |
70 | .Sh RETURN VALUES | |
2d21ac55 A |
71 | Upon successful completion, a value of 0 is returned. |
72 | Otherwise, a value of -1 is returned and the global integer variable | |
73 | .Va errno | |
74 | is set to indicate the error. | |
9bccf70c A |
75 | .Sh ERRORS |
76 | The | |
77 | .Fn bind | |
2d21ac55 | 78 | system call will fail if: |
9bccf70c | 79 | .Bl -tag -width Er |
2d21ac55 | 80 | .\" ========== |
9bccf70c A |
81 | .It Bq Er EACCES |
82 | The requested address is protected, and the current user | |
83 | has inadequate permission to access it. | |
2d21ac55 A |
84 | .\" ========== |
85 | .It Bq Er EADDRINUSE | |
86 | The specified address is already in use. | |
87 | .\" ========== | |
88 | .It Bq Er EADDRNOTAVAIL | |
89 | The specified address is not available from the local machine. | |
90 | .\" ========== | |
91 | .It Bq Er EAFNOSUPPORT | |
92 | .Fa address | |
93 | is not valid for the address family of | |
94 | .Fa socket . | |
95 | .\" ========== | |
96 | .It Bq Er EBADF | |
97 | .Fa socket | |
98 | is not a valid file descriptor. | |
99 | .\" ========== | |
100 | .It Bq Er EDESTADDRREQ | |
101 | .Fa socket | |
102 | is a null pointer. | |
103 | .\" ========== | |
9bccf70c A |
104 | .It Bq Er EFAULT |
105 | The | |
2d21ac55 | 106 | .Fa address |
9bccf70c A |
107 | parameter is not in a valid part of the user |
108 | address space. | |
2d21ac55 A |
109 | .\" ========== |
110 | .It Bq Er EINVAL | |
111 | .Fa socket | |
112 | is already bound to an address | |
113 | and the protocol does not support binding to a new address. | |
114 | Alternatively, | |
115 | .Fa socket | |
116 | may have been shut down. | |
117 | .\" ========== | |
118 | .It Bq Er ENOTSOCK | |
119 | .Fa socket | |
120 | does not refer to a socket. | |
121 | .\" ========== | |
122 | .It Bq Er EOPNOTSUPP | |
123 | .Fa socket | |
124 | is not of a type that can be bound to an address. | |
9bccf70c A |
125 | .El |
126 | .Pp | |
127 | The following errors are specific to binding names in the UNIX domain. | |
128 | .Bl -tag -width Er | |
2d21ac55 A |
129 | .\" ========== |
130 | .It Bq Er EACCES | |
131 | A component of the path prefix does not allow searching | |
132 | or the node's parent directory denies write permission. | |
133 | .\" ========== | |
fe8ab488 A |
134 | .It Bq Er EEXIST |
135 | A file already exists at the pathname. | |
136 | .Xr unlink 2 | |
137 | it first. | |
138 | .\" ========== | |
2d21ac55 A |
139 | .It Bq Er EIO |
140 | An I/O error occurred while making the directory entry | |
141 | or allocating the inode. | |
142 | .\" ========== | |
143 | .It Bq Er EISDIR | |
144 | An empty pathname was specified. | |
145 | .\" ========== | |
146 | .It Bq Er ELOOP | |
147 | Too many symbolic links were encountered in translating the pathname. | |
148 | This is taken to be indicative of a looping symbolic link. | |
149 | .\" ========== | |
9bccf70c A |
150 | .It Bq Er ENAMETOOLONG |
151 | A component of a pathname exceeded | |
152 | .Dv {NAME_MAX} | |
153 | characters, or an entire path name exceeded | |
154 | .Dv {PATH_MAX} | |
155 | characters. | |
2d21ac55 | 156 | .\" ========== |
9bccf70c | 157 | .It Bq Er ENOENT |
2d21ac55 A |
158 | A component of the path name does not refer to an existing file. |
159 | .\" ========== | |
160 | .It Bq Er ENOTDIR | |
161 | A component of the path prefix is not a directory. | |
162 | .\" ========== | |
9bccf70c A |
163 | .It Bq Er EROFS |
164 | The name would reside on a read-only file system. | |
9bccf70c | 165 | .El |
2d21ac55 A |
166 | .Sh LEGACY SYNOPSIS |
167 | .Fd #include <sys/types.h> | |
168 | .Fd #include <sys/socket.h> | |
169 | .Pp | |
170 | The include file | |
171 | .In sys/types.h | |
172 | is necessary. | |
9bccf70c A |
173 | .Sh SEE ALSO |
174 | .Xr connect 2 , | |
2d21ac55 | 175 | .Xr getsockname 2 , |
9bccf70c A |
176 | .Xr listen 2 , |
177 | .Xr socket 2 , | |
2d21ac55 | 178 | .Xr compat 5 |
9bccf70c A |
179 | .Sh HISTORY |
180 | The | |
181 | .Fn bind | |
182 | function call appeared in | |
183 | .Bx 4.2 . |