xref: /original-bsd/lib/libc/sys/bind.2 (revision 69c8e3e7)
1.\" Copyright (c) 1983, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)bind.2	8.1 (Berkeley) 06/04/93
7.\"
8.Dd
9.Dt BIND 2
10.Os BSD 4.2
11.Sh NAME
12.Nm bind
13.Nd bind a name to a socket
14.Sh SYNOPSIS
15.Fd #include <sys/types.h>
16.Fd #include <sys/socket.h>
17.Ft int
18.Fn bind "int s" "struct sockaddr *name" "int namelen"
19.Sh DESCRIPTION
20.Fn Bind
21assigns a name to an unnamed socket.
22When a socket is created
23with
24.Xr socket 2
25it exists in a name space (address family)
26but has no name assigned.
27.Fn Bind
28requests that
29.Fa name
30be assigned to the socket.
31.Sh NOTES
32Binding a name in the UNIX domain creates a socket in the file
33system that must be deleted by the caller when it is no longer
34needed (using
35.Xr unlink 2 ) .
36.Pp
37The rules used in name binding vary between communication domains.
38Consult the manual entries in section 4 for detailed information.
39.Sh RETURN VALUES
40If the bind is successful, a 0 value is returned.
41A return value of -1 indicates an error, which is
42further specified in the global
43.Va errno .
44.Sh ERRORS
45The
46.Fn bind
47call will fail if:
48.Bl -tag -width EADDRNOTAVA
49.It Bq Er EBADF
50.Fa S
51is not a valid descriptor.
52.It Bq Er ENOTSOCK
53.Fa S
54is not a socket.
55.It Bq Er EADDRNOTAVAIL
56The specified address is not available from the local machine.
57.It Bq Er EADDRINUSE
58The specified address is already in use.
59.It Bq Er EINVAL
60The socket is already bound to an address.
61.It Bq Er EACCES
62The requested address is protected, and the current user
63has inadequate permission to access it.
64.It Bq Er EFAULT
65The
66.Fa name
67parameter is not in a valid part of the user
68address space.
69.El
70.Pp
71The following errors are specific to binding names in the UNIX domain.
72.Bl -tag -width EADDRNOTAVA
73.It Bq Er ENOTDIR
74A component of the path prefix is not a directory.
75.It Bq Er EINVAL
76The pathname contains a character with the high-order bit set.
77.It Bq Er ENAMETOOLONG
78A component of a pathname exceeded 255 characters,
79or an entire path name exceeded 1023 characters.
80.It Bq Er ENOENT
81A prefix component of the path name does not exist.
82.It Bq Er ELOOP
83Too many symbolic links were encountered in translating the pathname.
84.It Bq Er EIO
85An I/O error occurred while making the directory entry or allocating the inode.
86.It Bq Er EROFS
87The name would reside on a read-only file system.
88.It Bq Er EISDIR
89An empty pathname was specified.
90.El
91.Sh SEE ALSO
92.Xr connect 2 ,
93.Xr listen 2 ,
94.Xr socket 2 ,
95.Xr getsockname 2
96.Sh HISTORY
97The
98.Nm
99function call appeared in
100.Bx 4.2 .
101