xref: /netbsd-src/lib/libc/sys/bind.2 (revision ce63d6c20fc4ec8ddc95c84bb229e3c4ecf82b69)
1.\" Copyright (c) 1983 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)bind.2	6.9 (Berkeley) 3/10/91
33.\"
34.Dd March 10, 1991
35.Dt BIND 2
36.Os BSD 4.2
37.Sh NAME
38.Nm bind
39.Nd bind a name to a socket
40.Sh SYNOPSIS
41.Fd #include <sys/types.h>
42.Fd #include <sys/socket.h>
43.Ft int
44.Fn bind "int s" "struct sockaddr *name" "int namelen"
45.Sh DESCRIPTION
46.Fn Bind
47assigns a name to an unnamed socket.
48When a socket is created
49with
50.Xr socket 2
51it exists in a name space (address family)
52but has no name assigned.
53.Fn Bind
54requests that
55.Fa name
56be assigned to the socket.
57.Sh NOTES
58Binding a name in the UNIX domain creates a socket in the file
59system that must be deleted by the caller when it is no longer
60needed (using
61.Xr unlink 2 ) .
62.Pp
63The rules used in name binding vary between communication domains.
64Consult the manual entries in section 4 for detailed information.
65.Sh RETURN VALUES
66If the bind is successful, a 0 value is returned.
67A return value of -1 indicates an error, which is
68further specified in the global
69.Va errno .
70.Sh ERRORS
71The
72.Fn bind
73call will fail if:
74.Bl -tag -width EADDRNOTAVA
75.It Bq Er EBADF
76.Fa S
77is not a valid descriptor.
78.It Bq Er ENOTSOCK
79.Fa S
80is not a socket.
81.It Bq Er EADDRNOTAVAIL
82The specified address is not available from the local machine.
83.It Bq Er EADDRINUSE
84The specified address is already in use.
85.It Bq Er EINVAL
86The socket is already bound to an address.
87.It Bq Er EACCES
88The requested address is protected, and the current user
89has inadequate permission to access it.
90.It Bq Er EFAULT
91The
92.Fa name
93parameter is not in a valid part of the user
94address space.
95.El
96.Pp
97The following errors are specific to binding names in the UNIX domain.
98.Bl -tag -width EADDRNOTAVA
99.It Bq Er ENOTDIR
100A component of the path prefix is not a directory.
101.It Bq Er EINVAL
102The pathname contains a character with the high-order bit set.
103.It Bq Er ENAMETOOLONG
104A component of a pathname exceeded 255 characters,
105or an entire path name exceeded 1023 characters.
106.It Bq Er ENOENT
107A prefix component of the path name does not exist.
108.It Bq Er ELOOP
109Too many symbolic links were encountered in translating the pathname.
110.It Bq Er EIO
111An I/O error occurred while making the directory entry or allocating the inode.
112.It Bq Er EROFS
113The name would reside on a read-only file system.
114.It Bq Er EISDIR
115An empty pathname was specified.
116.El
117.Sh SEE ALSO
118.Xr connect 2 ,
119.Xr listen 2 ,
120.Xr socket 2 ,
121.Xr getsockname 2
122.Sh HISTORY
123The
124.Nm
125function call appeared in
126.Bx 4.2 .
127