5331 want sockaddr(3SOCKET)
[illumos-gate.git] / usr / src / man / man3socket / bind.3socket
blob8c0f1cdfd79d0794455bb2b59ab5b7997ebc314f
1 '\" te
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"
8 .SH NAME
9 bind \- bind a name to a socket
10 .SH SYNOPSIS
11 .LP
12 .nf
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);
20 .fi
22 .SH DESCRIPTION
23 .LP
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.
28 .SH RETURN VALUES
29 .LP
30 Upon successful completion \fB0\fR is returned. Otherwise, \fB\(mi1\fR is
31 returned and \fBerrno\fR is set to indicate the error.
32 .SH ERRORS
33 .LP
34 The \fBbind()\fR function will fail if:
35 .sp
36 .ne 2
37 .na
38 \fB\fBEACCES\fR\fR
39 .ad
40 .RS 17n
41 The requested address is protected, and \fB{PRIV_NET_PRIVADDR}\fR is not
42 asserted in the effective set of the current process.
43 .RE
45 .sp
46 .ne 2
47 .na
48 \fB\fBEADDRINUSE\fR\fR
49 .ad
50 .RS 17n
51 The specified address is already in use.
52 .RE
54 .sp
55 .ne 2
56 .na
57 \fB\fBEADDRNOTAVAIL\fR\fR
58 .ad
59 .RS 17n
60 The specified address is not available on the local machine.
61 .RE
63 .sp
64 .ne 2
65 .na
66 \fB\fBEBADF\fR\fR
67 .ad
68 .RS 17n
69 \fIs\fR is not a valid descriptor.
70 .RE
72 .sp
73 .ne 2
74 .na
75 \fB\fBEINVAL\fR\fR
76 .ad
77 .RS 17n
78 \fInamelen\fR is not the size of a valid address for the specified address
79 family.
80 .sp
81 The socket is already bound to an address.
82 .sp
83 Socket options are inconsistent with port attributes.
84 .RE
86 .sp
87 .ne 2
88 .na
89 \fB\fBENOSR\fR\fR
90 .ad
91 .RS 17n
92 There were insufficient \fBSTREAMS\fR resources for the operation to complete.
93 .RE
95 .sp
96 .ne 2
97 .na
98 \fB\fBENOTSOCK\fR\fR
99 .ad
100 .RS 17n
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:
108 .ne 2
110 \fB\fBEACCES\fR\fR
112 .RS 11n
113 Search permission is denied for a component of the path prefix of the pathname
114 in \fIname\fR.
118 .ne 2
120 \fB\fBEIO\fR\fR
122 .RS 11n
123 An I/O error occurred while making the directory entry or allocating the inode.
127 .ne 2
129 \fB\fBEISDIR\fR\fR
131 .RS 11n
132 A null pathname was specified.
136 .ne 2
138 \fB\fBELOOP\fR\fR
140 .RS 11n
141 Too many symbolic links were encountered in translating the pathname in
142 \fIname\fR.
146 .ne 2
148 \fB\fBENOENT\fR\fR
150 .RS 11n
151 A component of the path prefix of the pathname in \fIname\fR does not exist.
155 .ne 2
157 \fB\fBENOTDIR\fR\fR
159 .RS 11n
160 A component of the path prefix of the pathname in \fIname\fR is not a
161 directory.
165 .ne 2
167 \fB\fBEROFS\fR\fR
169 .RS 11n
170 The inode would reside on a read-only file system.
173 .SH ATTRIBUTES
175 See \fBattributes\fR(5) for descriptions of the following attributes:
180 box;
181 c | c
182 l | l .
183 ATTRIBUTE TYPE  ATTRIBUTE VALUE
185 MT-Level        Safe
188 .SH SEE ALSO
190 \fBunlink\fR(2), \fBsocket\fR(3SOCKET), \fBsockaddr\fR(3SOCKET),
191 \fBattributes\fR(5), \fBprivileges\fR(5), \fBsocket.h\fR(3HEAD)
192 .SH NOTES
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.