Commit | Line | Data |
---|---|---|
1418f8f7 KM |
1 | .\" Copyright (c) 1983 Regents of the University of California. |
2 | .\" All rights reserved. The Berkeley software License Agreement | |
3 | .\" specifies the terms and conditions for redistribution. | |
4 | .\" | |
efd03614 | 5 | .\" @(#)bind.2 6.6 (Berkeley) %G% |
1418f8f7 | 6 | .\" |
27b162cf | 7 | .TH BIND 2 "" |
1418f8f7 KM |
8 | .UC 5 |
9 | .SH NAME | |
10 | bind \- bind a name to a socket | |
11 | .SH SYNOPSIS | |
12 | .nf | |
13 | .ft B | |
14 | #include <sys/types.h> | |
15 | #include <sys/socket.h> | |
16 | .PP | |
17 | .ft B | |
18 | bind(s, name, namelen) | |
19 | int s; | |
20 | struct sockaddr *name; | |
21 | int namelen; | |
22 | .fi | |
23 | .SH DESCRIPTION | |
24 | .I Bind | |
25 | assigns a name to an unnamed socket. | |
26 | When a socket is created | |
27 | with | |
28 | .IR socket (2) | |
29 | it exists in a name space (address family) | |
30 | but has no name assigned. | |
31 | .I Bind | |
efd03614 AH |
32 | requests that |
33 | .IR name | |
1418f8f7 KM |
34 | be assigned to the socket. |
35 | .SH NOTES | |
36 | Binding a name in the UNIX domain creates a socket in the file | |
d84f45ef | 37 | system that must be deleted by the caller when it is no longer |
1418f8f7 KM |
38 | needed (using |
39 | .IR unlink (2)). | |
1418f8f7 KM |
40 | .PP |
41 | The rules used in name binding vary between communication domains. | |
42 | Consult the manual entries in section 4 for detailed information. | |
43 | .SH "RETURN VALUE | |
44 | If the bind is successful, a 0 value is returned. | |
45 | A return value of \-1 indicates an error, which is | |
46 | further specified in the global \fIerrno\fP. | |
47 | .SH ERRORS | |
48 | The \fIbind\fP call will fail if: | |
49 | .TP 20 | |
50 | [EBADF] | |
51 | \fIS\fP is not a valid descriptor. | |
52 | .TP 20 | |
53 | [ENOTSOCK] | |
54 | \fIS\fP is not a socket. | |
55 | .TP 20 | |
56 | [EADDRNOTAVAIL] | |
57 | The specified address is not available from the local machine. | |
58 | .TP 20 | |
59 | [EADDRINUSE] | |
60 | The specified address is already in use. | |
61 | .TP 20 | |
62 | [EINVAL] | |
63 | The socket is already bound to an address. | |
64 | .TP 20 | |
435c3f78 | 65 | [EACCES] |
1418f8f7 KM |
66 | The requested address is protected, and the current user |
67 | has inadequate permission to access it. | |
68 | .TP 20 | |
69 | [EFAULT] | |
70 | The \fIname\fP parameter is not in a valid part of the user | |
71 | address space. | |
b5984ffe KM |
72 | .PP |
73 | The following errors are specific to binding names in the UNIX domain. | |
b5984ffe KM |
74 | .TP 15 |
75 | [ENOTDIR] | |
76 | A component of the path prefix is not a directory. | |
77 | .TP 15 | |
78 | [EINVAL] | |
79 | The pathname contains a character with the high-order bit set. | |
80 | .TP 15 | |
81 | [ENAMETOOLONG] | |
82 | A component of a pathname exceeded 255 characters, | |
83 | or an entire path name exceeded 1023 characters. | |
84 | .TP 15 | |
85 | [ENOENT] | |
86 | A prefix component of the path name does not exist. | |
87 | .TP 15 | |
88 | [ELOOP] | |
89 | Too many symbolic links were encountered in translating the pathname. | |
90 | .TP 15 | |
91 | [EIO] | |
92 | An I/O error occurred while making the directory entry or allocating the inode. | |
93 | .TP 15 | |
94 | [EROFS] | |
95 | The name would reside on a read-only file system. | |
96 | .TP 15 | |
97 | [EISDIR] | |
98 | A null pathname was specified. | |
1418f8f7 KM |
99 | .SH SEE ALSO |
100 | connect(2), listen(2), socket(2), getsockname(2) |