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