5331 want sockaddr(3SOCKET)
[illumos-gate.git] / usr / src / man / man3xnet / bind.3xnet
blob12be69fbe34f7d7fe5bef8b419ae12856a071630
1 '\" te
2 .\" Copyright (c) 1997, The Open Group. All Rights Reserved.
3 .\" Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
4 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
7 .\"  This notice shall appear on any product containing this material.
8 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
9 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
10 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
11 .TH BIND 3XNET "Feb 20, 2003"
12 .SH NAME
13 bind \- bind a name to a socket
14 .SH SYNOPSIS
15 .LP
16 .nf
17 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lxnet\fR [ \fIlibrary\fR ... ]
18 #include <sys/socket.h>
20 \fBint\fR \fBbind\fR(\fBint\fR \fIsocket\fR, \fBconst struct sockaddr *\fR\fIaddress\fR,
21      \fBsocklen_t\fR \fIaddress_len\fR);
22 .fi
24 .SH DESCRIPTION
25 .LP
26 The \fBbind()\fR function assigns an \fIaddress\fR to an unnamed socket.
27 Sockets created with \fBsocket\fR(3XNET) function are initially unnamed. They
28 are identified only by their address family.
29 .sp
30 .LP
31 The function takes the following arguments:
32 .sp
33 .ne 2
34 .na
35 \fB\fIsocket\fR\fR
36 .ad
37 .RS 15n
38 Specifies the file descriptor of the socket to be bound.
39 .RE
41 .sp
42 .ne 2
43 .na
44 \fB\fIaddress\fR\fR
45 .ad
46 .RS 15n
47 Points to a \fBsockaddr\fR structure containing the address to be bound to the
48 socket.  The length and format of the address depend on the address family of
49 the socket.
50 .RE
52 .sp
53 .ne 2
54 .na
55 \fB\fIaddress_len\fR\fR
56 .ad
57 .RS 15n
58 Specifies the length of the \fBsockaddr\fR structure pointed to by the
59 \fIaddress\fR argument.
60 .RE
62 .sp
63 .LP
64 The socket in use may require the process to have appropriate privileges to use
65 the \fBbind()\fR function.
66 .SH USAGE
67 .LP
68 An application program can retrieve the assigned socket name with the
69 \fBgetsockname\fR(3XNET) function.
70 .SH RETURN VALUES
71 .LP
72 Upon successful completion, \fBbind()\fR returns 0.  Otherwise, \(mi1 is
73 returned and \fBerrno\fR is set to indicate the error.
74 .SH ERRORS
75 .LP
76 The \fBbind()\fR function will fail if:
77 .sp
78 .ne 2
79 .na
80 \fB\fBEADDRINUSE\fR\fR
81 .ad
82 .RS 17n
83 The specified address is already in use.
84 .RE
86 .sp
87 .ne 2
88 .na
89 \fB\fBEADDRNOTAVAIL\fR\fR
90 .ad
91 .RS 17n
92 The specified address is not available from the local machine.
93 .RE
95 .sp
96 .ne 2
97 .na
98 \fB\fBEAFNOSUPPORT\fR\fR
99 .ad
100 .RS 17n
101 The specified address is not a valid address for the address family of the
102 specified socket.
106 .ne 2
108 \fB\fBEBADF\fR\fR
110 .RS 17n
111 The \fIsocket\fR argument is not a valid file descriptor.
115 .ne 2
117 \fB\fBEFAULT\fR\fR
119 .RS 17n
120 The  \fIaddress\fR argument can not be accessed.
124 .ne 2
126 \fB\fBEINVAL\fR\fR
128 .RS 17n
129 The socket is already bound to an address, and the protocol does not support
130 binding to a new address; or the socket has been shut down.
134 .ne 2
136 \fB\fBENOTSOCK\fR\fR
138 .RS 17n
139 The \fIsocket\fR argument does not refer to a socket.
143 .ne 2
145 \fB\fBEOPNOTSUPP\fR\fR
147 .RS 17n
148 The socket type of the specified socket does not support binding to an address.
153 If the address family of the socket is AF_UNIX, then \fBbind()\fR will fail if:
155 .ne 2
157 \fB\fBEACCES\fR\fR
159 .RS 16n
160 A component of the path prefix denies search permission, or the requested name
161 requires writing in a directory with a mode that denies write permission.
165 .ne 2
167 \fB\fBEDESTADDRREQ\fR\fR
171 \fB\fBEISDIR\fR\fR
173 .RS 16n
174 The \fIaddress\fR argument is a null pointer.
178 .ne 2
180 \fB\fBEIO\fR\fR
182 .RS 16n
183 An I/O error occurred.
187 .ne 2
189 \fB\fBELOOP\fR\fR
191 .RS 16n
192 Too many symbolic links were encountered in translating the pathname in
193 \fIaddress.\fR
197 .ne 2
199 \fB\fBENAMETOOLONG\fR\fR
201 .RS 16n
202 A component of a pathname exceeded \fINAME_MAX\fR characters, or an entire
203 pathname exceeded \fIPATH_MAX\fR characters.
207 .ne 2
209 \fB\fBENOENT\fR\fR
211 .RS 16n
212 A component of the pathname does not name an existing file or the pathname is
213 an empty string.
217 .ne 2
219 \fB\fBENOTDIR\fR\fR
221 .RS 16n
222 A component of the path prefix of the pathname in \fIaddress\fR is not a
223 directory.
227 .ne 2
229 \fB\fBEROFS\fR\fR
231 .RS 16n
232 The name would reside on a read-only filesystem.
237 The \fBbind()\fR function may fail if:
239 .ne 2
241 \fB\fBEACCES\fR\fR
243 .RS 16n
244 The specified address is protected, and \fB{PRIV_NET_PRIVADOR}\fR is not
245 asserted in the effective set of the current process.
249 .ne 2
251 \fB\fBEINVAL\fR\fR
253 .RS 16n
254 The \fIaddress_len\fR argument is not a valid length for the address family.
258 .ne 2
260 \fB\fBEISCONN\fR\fR
262 .RS 16n
263 The socket is already connected.
267 .ne 2
269 \fB\fBENAMETOOLONG\fR\fR
271 .RS 16n
272 Pathname resolution of a symbolic link produced an intermediate result whose
273 length exceeds \fIPATH_MAX\fR.
277 .ne 2
279 \fB\fBENOBUFS\fR\fR
281 .RS 16n
282 Insufficient resources were available to complete the call.
286 .ne 2
288 \fB\fBENOSR\fR\fR
290 .RS 16n
291 There were insufficient STREAMS resources for the operation to complete.
294 .SH ATTRIBUTES
296 See \fBattributes\fR(5) for descriptions of the following attributes:
301 box;
302 c | c
303 l | l .
304 ATTRIBUTE TYPE  ATTRIBUTE VALUE
306 Interface Stability     Standard
308 MT-Level        MT-Safe
311 .SH SEE ALSO
313 \fBsockaddr\fR(3SOCKET),
314 \fBconnect\fR(3XNET), \fBgetsockname\fR(3XNET), \fBlisten\fR(3XNET),
315 \fBsocket\fR(3XNET), \fBattributes\fR(5), \fBprivileges\fR(5),
316 \fBstandards\fR(5)