2 .\" Copyright (C) 2009, Sun Microsystems, Inc. All Rights Reserved
3 .\" Copyright 1989 AT&T
4 .\" 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. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
5 .\" See the License for the specific language governing permissions and limitations under the License. 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
6 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH BIND 3SOCKET "May 11, 2009"
9 bind \- bind a name to a socket
13 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lsocket\fR \fB -lnsl \fR [ \fIlibrary\fR ... ]
14 #include <sys/types.h>
15 #include <sys/socket.h>
19 \fBint\fR \fBbind\fR(\fBint\fR \fIs\fR, \fBconst struct sockaddr *\fR\fIname\fR, \fBint\fR \fInamelen\fR);
24 The \fBbind()\fR function assigns a name to an unnamed socket. When a socket is
25 created with \fBsocket\fR(3SOCKET), it exists in a name space (address family)
26 but has no name assigned. The \fBbind()\fR function requests that the name
27 pointed to by \fIname\fR be assigned to the socket.
30 Upon successful completion \fB0\fR is returned. Otherwise, \fB\(mi1\fR is
31 returned and \fBerrno\fR is set to indicate the error.
34 The \fBbind()\fR function will fail if:
41 The requested address is protected, and \fB{PRIV_NET_PRIVADDR}\fR is not
42 asserted in the effective set of the current process.
48 \fB\fBEADDRINUSE\fR\fR
51 The specified address is already in use.
57 \fB\fBEADDRNOTAVAIL\fR\fR
60 The specified address is not available on the local machine.
69 \fIs\fR is not a valid descriptor.
78 \fInamelen\fR is not the size of a valid address for the specified address
81 The socket is already bound to an address.
83 Socket options are inconsistent with port attributes.
92 There were insufficient \fBSTREAMS\fR resources for the operation to complete.
101 \fIs\fR is a descriptor for a file, not a socket.
106 The following errors are specific to binding names in the UNIX domain:
113 Search permission is denied for a component of the path prefix of the pathname
123 An I/O error occurred while making the directory entry or allocating the inode.
132 A null pathname was specified.
141 Too many symbolic links were encountered in translating the pathname in
151 A component of the path prefix of the pathname in \fIname\fR does not exist.
160 A component of the path prefix of the pathname in \fIname\fR is not a
170 The inode would reside on a read-only file system.
175 See \fBattributes\fR(5) for descriptions of the following attributes:
183 ATTRIBUTE TYPE ATTRIBUTE VALUE
190 \fBunlink\fR(2), \fBsocket\fR(3SOCKET), \fBsockaddr\fR(3SOCKET),
191 \fBattributes\fR(5), \fBprivileges\fR(5), \fBsocket.h\fR(3HEAD)
194 Binding a name in the UNIX domain creates a socket in the file system that must
195 be deleted by the caller when it is no longer needed by using \fBunlink\fR(2).
198 The rules used in name binding vary between communication domains.