xref: /netbsd-src/lib/libc/sys/bind.2 (revision bada23909e740596d0a3785a73bd3583a9807fb8)
1.\"	$NetBSD: bind.2,v 1.11 1999/02/10 18:20:02 kleink 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
43.Fd #include <sys/types.h>
44.Fd #include <sys/socket.h>
45.Ft int
46.Fn bind "int s" "const struct sockaddr *name" "socklen_t namelen"
47.Sh DESCRIPTION
48.Fn bind
49assigns a name to an unnamed socket.
50When a socket is created
51with
52.Xr socket 2
53it exists in a name space (address family)
54but has no name assigned.
55.Fn bind
56requests that
57.Fa name
58be assigned to the socket.
59.Sh NOTES
60Binding a name in the
61.Ux
62domain creates a socket in the file
63system that must be deleted by the caller when it is no longer
64needed (using
65.Xr unlink 2 ) .
66.Pp
67The rules used in name binding vary between communication domains.
68Consult the manual entries in section 4 for detailed information.
69.Sh RETURN VALUES
70If the bind is successful, a 0 value is returned.
71A return value of -1 indicates an error, which is
72further specified in the global
73.Va errno .
74.Sh ERRORS
75The
76.Fn bind
77call will fail if:
78.Bl -tag -width Er
79.It Bq Er EBADF
80.Fa s
81is not a valid descriptor.
82.It Bq Er ENOTSOCK
83.Fa s
84is not a socket.
85.It Bq Er EADDRNOTAVAIL
86The specified address is not available from the local machine.
87.It Bq Er EADDRINUSE
88The specified address is already in use.
89.It Bq Er EINVAL
90The socket is already bound to an address.
91.It Bq Er EACCES
92The requested address is protected, and the current user
93has inadequate permission to access it.
94.It Bq Er EFAULT
95The
96.Fa name
97parameter is not in a valid part of the user
98address space.
99.El
100.Pp
101The following errors are specific to binding names in the
102.Ux
103domain.
104.Bl -tag -width Er
105.It Bq Er ENOTDIR
106A component of the path prefix is not a directory.
107.It Bq Er ENAMETOOLONG
108A component of a pathname exceeded
109.Dv {NAME_MAX}
110characters, or an entire path name exceeded
111.Dv {PATH_MAX}
112characters.
113.It Bq Er ENOENT
114A prefix component of the path name does not exist.
115.It Bq Er ELOOP
116Too many symbolic links were encountered in translating the pathname.
117.It Bq Er EIO
118An I/O error occurred while making the directory entry or allocating the inode.
119.It Bq Er EROFS
120The name would reside on a read-only file system.
121.It Bq Er EISDIR
122An empty pathname was specified.
123.El
124.Sh SEE ALSO
125.Xr connect 2 ,
126.Xr listen 2 ,
127.Xr socket 2 ,
128.Xr getsockname 2
129.Sh HISTORY
130The
131.Fn bind
132function call appeared in
133.Bx 4.2 .
134