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"
13 bind \- bind a name to a socket
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);
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.
31 The function takes the following arguments:
38 Specifies the file descriptor of the socket to be bound.
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
55 \fB\fIaddress_len\fR\fR
58 Specifies the length of the \fBsockaddr\fR structure pointed to by the
59 \fIaddress\fR argument.
64 The socket in use may require the process to have appropriate privileges to use
65 the \fBbind()\fR function.
68 An application program can retrieve the assigned socket name with the
69 \fBgetsockname\fR(3XNET) function.
72 Upon successful completion, \fBbind()\fR returns 0. Otherwise, \(mi1 is
73 returned and \fBerrno\fR is set to indicate the error.
76 The \fBbind()\fR function will fail if:
80 \fB\fBEADDRINUSE\fR\fR
83 The specified address is already in use.
89 \fB\fBEADDRNOTAVAIL\fR\fR
92 The specified address is not available from the local machine.
98 \fB\fBEAFNOSUPPORT\fR\fR
101 The specified address is not a valid address for the address family of the
111 The \fIsocket\fR argument is not a valid file descriptor.
120 The \fIaddress\fR argument can not be accessed.
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.
139 The \fIsocket\fR argument does not refer to a socket.
145 \fB\fBEOPNOTSUPP\fR\fR
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:
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.
167 \fB\fBEDESTADDRREQ\fR\fR
174 The \fIaddress\fR argument is a null pointer.
183 An I/O error occurred.
192 Too many symbolic links were encountered in translating the pathname in
199 \fB\fBENAMETOOLONG\fR\fR
202 A component of a pathname exceeded \fINAME_MAX\fR characters, or an entire
203 pathname exceeded \fIPATH_MAX\fR characters.
212 A component of the pathname does not name an existing file or the pathname is
222 A component of the path prefix of the pathname in \fIaddress\fR is not a
232 The name would reside on a read-only filesystem.
237 The \fBbind()\fR function may fail if:
244 The specified address is protected, and \fB{PRIV_NET_PRIVADOR}\fR is not
245 asserted in the effective set of the current process.
254 The \fIaddress_len\fR argument is not a valid length for the address family.
263 The socket is already connected.
269 \fB\fBENAMETOOLONG\fR\fR
272 Pathname resolution of a symbolic link produced an intermediate result whose
273 length exceeds \fIPATH_MAX\fR.
282 Insufficient resources were available to complete the call.
291 There were insufficient STREAMS resources for the operation to complete.
296 See \fBattributes\fR(5) for descriptions of the following attributes:
304 ATTRIBUTE TYPE ATTRIBUTE VALUE
306 Interface Stability Standard
313 \fBsockaddr\fR(3SOCKET),
314 \fBconnect\fR(3XNET), \fBgetsockname\fR(3XNET), \fBlisten\fR(3XNET),
315 \fBsocket\fR(3XNET), \fBattributes\fR(5), \fBprivileges\fR(5),