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