OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / release / man2 / bind.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
4 .\" Portions extracted from /usr/include/sys/socket.h, which does not have
5 .\" any authorship information in it.  It is probably available under the GPL.
6 .\"
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
10 .\"
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
15 .\"
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein.  The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
22 .\" professionally.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
26 .\"
27 .\"
28 .\" Other portions are from the 6.9 (Berkeley) 3/10/91 man page:
29 .\"
30 .\" Copyright (c) 1983 The Regents of the University of California.
31 .\" All rights reserved.
32 .\"
33 .\" Redistribution and use in source and binary forms, with or without
34 .\" modification, are permitted provided that the following conditions
35 .\" are met:
36 .\" 1. Redistributions of source code must retain the above copyright
37 .\"    notice, this list of conditions and the following disclaimer.
38 .\" 2. Redistributions in binary form must reproduce the above copyright
39 .\"    notice, this list of conditions and the following disclaimer in the
40 .\"    documentation and/or other materials provided with the distribution.
41 .\" 3. All advertising materials mentioning features or use of this software
42 .\"    must display the following acknowledgement:
43 .\"     This product includes software developed by the University of
44 .\"     California, Berkeley and its contributors.
45 .\" 4. Neither the name of the University nor the names of its contributors
46 .\"    may be used to endorse or promote products derived from this software
47 .\"    without specific prior written permission.
48 .\"
49 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 .\" SUCH DAMAGE.
60 .\"
61 .\" Modified Mon Oct 21 23:05:29 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
62 .\" Modified 1998 by Andi Kleen
63 .\" $Id: bind.2,v 1.3 1999/04/23 19:56:07 freitag Exp $
64 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
65 .\"
66 .\" Japanese Version Copyright (c) 1996 Yosiaki Yanagihara
67 .\"         all rights reserved.
68 .\" Translated 1996-06-25, Yosiaki Yanagihara <yosiaki@bsd2.kbnes.nec.co.jp>
69 .\" Modified 1997-11-06, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
70 .\" Modified 1999-08-02, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
71 .\" Updated 2005-02-03, Yuichi SATO <ysato444@yahoo.co.jp>
72 .\" Updated 2005-12-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
73 .\" Updated 2006-07-19, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.36
74 .\" Updated 2007-06-13, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.55
75 .\" Updated 2008-02-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.77
76 .\"
77 .TH BIND 2 2007-12-28 "Linux" "Linux Programmer's Manual"
78 .SH Ì¾Á°
79 bind \- ¥½¥±¥Ã¥È¤Ë̾Á°¤ò¤Ä¤±¤ë
80 .SH ½ñ¼°
81 .nf
82 .BR "#include <sys/types.h>" "          /* ¡ÖÃí°Õ¡×»²¾È */"
83 .B #include <sys/socket.h>
84 .sp
85 .BI "int bind(int " sockfd ", const struct sockaddr *" addr ,
86 .BI "         socklen_t " addrlen );
87 .fi
88 .SH ÀâÌÀ
89 .BR socket (2)
90 ¤Ç¥½¥±¥Ã¥È¤¬ºîÀ®¤µ¤ì¤¿¤È¤­¡¢¤½¤Î¥½¥±¥Ã¥È¤Ï̾Á°¶õ´Ö (¥¢¥É¥ì¥¹¡¦¥Õ¥¡¥ß¥ê¡¼) ¤Ë
91 ¸ºß¤¹¤ë¤¬¡¢¥¢¥É¥ì¥¹¤Ï³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤Ê¤¤¡£
92 .BR bind ()
93 ¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
94 .I sockfd
95 ¤Ç»²¾È¤µ¤ì¤ë¥½¥±¥Ã¥È¤Ë
96 .I addr
97 ¤Ç»ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¤ò³ä¤êÅö¤Æ¤ë¡£
98 .I addrlen
99 ¤Ë¤Ï
100 .I addr
101 ¤¬»Ø¤¹¥¢¥É¥ì¥¹¹½Â¤ÂΤΥµ¥¤¥º¤ò¥Ð¥¤¥Èñ°Ì¤Ç»ØÄꤹ¤ë¡£
102 ÅÁÅýŪ¤Ë¤³¤ÎÁàºî¤Ï
103 ¡Ö¥½¥±¥Ã¥È¤Ë̾Á°¤ò¤Ä¤±¤ë¡×
104 ¤È¸Æ¤Ð¤ì¤ë¡£
105 .PP
106 .B SOCK_STREAM
107 ¥½¥±¥Ã¥È¤¬Àܳ¤ò¼õ¤±ÉÕ¤±¤é¤ì¤ë¤è¤¦¤Ë¤¹¤ë¤Ë¤Ï
108 .RB ( accept (2)
109 ¤ò»²¾È)¡¢Ä̾綠¤ÎÁ°¤Ë
110 .BR bind ()
111 ¤ò»ÈÍѤ·¤Æ¥í¡¼¥«¥ë¥¢¥É¥ì¥¹¤ò³ä¤êÅö¤Æ¤ëɬÍפ¬¤¢¤ë¡£
112
113 ̾Á°ÉÕ¤±¤Î¥ë¡¼¥ë¤Ï¥¢¥É¥ì¥¹¡¦¥Õ¥¡¥ß¥ê¡¼¤´¤È¤Ë°Û¤Ê¤Ã¤Æ¤¤¤ë¡£¾ÜºÙ¤Ê¾ðÊó¤Ï
114 Âè 7 ¾Ï¤Î³Æ¥Þ¥Ë¥å¥¢¥ë¤ò»²¾È¤¹¤ë¤³¤È¡£
115 .B AF_INET
116 ¤Ï
117 .BR ip (7)
118 ¤ò¡¢
119 .B AF_INET6
120 ¤Ï
121 .BR ipv6 (7)
122 ¤ò¡¢
123 .B AF_UNIX
124 ¤Ï
125 .BR unix (7)
126 ¤ò¡¢
127 .B AF_APPLETALK
128 ¤Ï
129 .BR ddp (7)
130 ¤ò¡¢
131 .B AF_PACKET
132 ¤Ï
133 .BR packet (7)
134 ¤ò¡¢
135 .B AF_X25
136 ¤Ï
137 .BR x25 (7)
138 ¤ò¡¢
139 .B AF_NETLINK
140 ¤Ï
141 .BR netlink (7)
142 ¤ò»²¾È¡£
143
144 .I addr
145 °ú¤­¿ô¤Ë¼ÂºÝ¤Ë¤É¤Î¤è¤¦¤Ê¹½Â¤ÂΤ¬ÅϤµ¤ì¤ë¤«¤Ï¡¢
146 ¥¢¥É¥ì¥¹¡¦¥Õ¥¡¥ß¥ê¡¼¤Ë°Í¸¤¹¤ë¡£
147 .I sockaddr
148 ¹½Â¤ÂΤϰʲ¼¤Î¤è¤¦¤Ê´¶¤¸¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
149 .in +4n
150 .nf
151
152 struct sockaddr {
153     sa_family_t sa_family;
154     char        sa_data[14];
155 }
156
157 .fi
158 .in
159 ¤³¤Î¹½Â¤ÂΤϡ¢
160 .I addr
161 ¤ËÅϤµ¤ì¤ë¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤ò¥­¥ã¥¹¥È¤·¡¢
162 ¥³¥ó¥Ñ¥¤¥é¤Î·Ù¹ð¥á¥Ã¥»¡¼¥¸¤òÍÞ¤¨¤ë¤¿¤á¤À¤±¤Ë¸ºß¤¹¤ë¡£
163 ²¼µ­¤Î¡ÖÎã¡×¤ò»²¾È¡£
164 .SH ÊÖ¤êÃÍ
165 À®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤¹¡£
166 ¼ºÇÔ¤¹¤ë¤È \-1 ¤òÊÖ¤·¡¢
167 .I errno
168 ¤òŬÀÚ¤ËÀßÄꤹ¤ë¡£
169 .SH ¥¨¥é¡¼
170 .TP
171 .B EACCES
172 .\" e.g., privileged port in AF_INET domain
173 ¤½¤Î¥¢¥É¥ì¥¹¤ÏÊݸ¤ì¤Æ¤¤¤Æ¡¢¤«¤Ä¥æ¡¼¥¶¤¬¥¹¡¼¥Ñ¡¼¥æ¡¼¥¶¤Ç¤Ï¤Ê¤¤¡£
174 .TP
175 .B EADDRINUSE
176 »ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¤¬´û¤Ë»ÈÍÑÃæ¤Ç¤¢¤ë¡£
177 .TP
178 .B EBADF
179 .I sockfd
180 ¤¬ÉÔÀµ¤Ê¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤¢¤ë¡£
181 .TP
182 .B EINVAL
183 ¥½¥±¥Ã¥È¤¬¤¹¤Ç¤Ë¥¢¥É¥ì¥¹¤Ë·ë¤Ó¤Ä¤± (bind) ¤é¤ì¤Æ¤¤¤ë¡£
184 .\" ¤³¤ì¤Ï¾­ÍèÊѹ¹¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
185 .\" ¾Ü¤·¤¯¤Ï
186 .\" .I linux/unix/sock.c
187 .\" ¤ò»²¾È¤¹¤ë¤³¤È¡£
188 .B ENOTSOCK
189 .I sockfd
190 ¤¬¥Õ¥¡¥¤¥ë¤ËÂФ¹¤ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¡¢¥½¥±¥Ã¥È¤ËÂФ¹¤ë¤â¤Î¤Ç¤Ï¤Ê¤¤¡£
191 .PP
192 °Ê²¼¤Î¥¨¥é¡¼¤Ï Unix¥É¥á¥¤¥ó
193 .RB ( AF_UNIX )
194 ¤Î¥½¥±¥Ã¥ÈÆÃÍ­¤Ç¤¢¤ë:
195 .TP
196 .B EACCES
197 ¥Ñ¥¹Ì¾¤Î¹½À®Í×ÁǤ˸¡º÷µö²Ä (search permission) ¤¬¤Ê¤¤
198 .RB ( path_resolution (7)
199 ¤â»²¾È¤¹¤ë¤³¤È)¡£
200 .TP
201 .B EADDRNOTAVAIL
202 ¸ºß¤·¤Ê¤¤¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤¬Í׵ᤵ¤ì¤¿¤«¡¢Í׵ᤵ¤ì¤¿¥¢¥É¥ì¥¹¤¬
203 ¥í¡¼¥«¥ë¤Ç¤Ï¤Ê¤«¤Ã¤¿¡£
204 .TP
205 .B EFAULT
206 .I addr
207 ¤¬¥æ¡¼¥¶¤Î¥¢¥¯¥»¥¹²Äǽ¤Ê¥¢¥É¥ì¥¹¶õ´Ö¤Î³°¤ò»Ø¤·¤Æ¤¤¤ë¡£
208 .TP
209 .B EINVAL
210 .I addrlen
211 ¤¬ÉÔÀµ¤Ç¤¢¤ë¤«¡¢¥½¥±¥Ã¥È¤¬
212 .B AF_UNIX
213 ¥Õ¥¡¥ß¥ê¡¼¤Ç¤Ï¤Ê¤¤¡£
214 .TP
215 .B ELOOP
216 .I addr
217 ¤ò²ò·è¤¹¤ëºÝ¤ËÁø¶ø¤·¤¿¥·¥ó¥Ü¥ê¥Ã¥¯¡¦¥ê¥ó¥¯¤¬Â¿²á¤®¤ë¡£
218 .TP
219 .B ENAMETOOLONG
220 .I addr
221 ¤¬Ä¹²á¤®¤ë¡£
222 .TP
223 .B ENOENT
224 ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤¤¡£
225 .TP
226 .B ENOMEM
227 ¥«¡¼¥Í¥ë¤Ë¡¢ÍøÍѲÄǽ¤Ê¥á¥â¥ê¡¼¤¬½½Ê¬¤Ë¤Ê¤¤¡£
228 .TP
229 .B ENOTDIR
230 ¥Ñ¥¹Ì¾¤Î¹½À®Í×ÁǤ¬¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤Ï¤Ê¤¤¡£
231 .TP
232 .B EROFS
233 ¥½¥±¥Ã¥È inode ¤¬Æɤ߹þ¤ßÀìÍѤΥե¡¥¤¥ë¥·¥¹¥Æ¥à¾å¤Ë¤¢¤ë¡£
234 .SH ½àµò
235 SVr4, 4.4BSD, POSIX.1-2001
236 .RB ( bind ()
237 ¤Ï 4.2BSD ¤ÇºÇ½é¤Ë¸½¤ï¤ì¤¿)¡£
238 .\" SVr4 ¤Ë¤Ï¾¤Ë¡¢°ìÈ̤Υ¨¥é¡¼¾õÂÖ
239 .\" .B ENOSR
240 .\" µÚ¤Ó Unix ¥É¥á¥¤¥ó¤Î¥¨¥é¡¼¾õÂÖ
241 .\" .BR EIO ,
242 .\" .B EISDIR
243 .\" ¤Ë¤Ä¤¤¤Æ¤Îµ­½Ò¤¬¤¢¤ë¡£
244 .SH Ãí°Õ
245 POSIX.1-2001 ¤Ç¤Ï
246 .I <sys/types.h>
247 ¤Î¥¤¥ó¥¯¥ë¡¼¥É¤Ïɬ¿Ü¤È¤µ¤ì¤Æ¤ª¤é¤º¡¢
248 Linux ¤Ç¤Ï¤³¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤ÏɬÍפǤϤʤ¤¡£
249 ¤·¤«¤·¡¢Îò»ËŪ¤Ë¤Ï¡¢¤¤¤¯¤Ä¤«¤Î¼ÂÁõ (BSD ·Ï) ¤Ç¤³¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤¬
250 ɬÍפǤ¢¤ê¡¢°Ü¿¢À­¤¬É¬Íפʥ¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¤³¤Î¥Õ¥¡¥¤¥ë¤ò
251 ¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤Î¤¬¸­ÌÀ¤Ç¤¢¤í¤¦¡£
252
253 .BR bind ()
254 ¤Î»°ÈÖÌܤΰú¤­¿ô¤Ï (4.x BSD ¤ä libc4, libc5 ¤ÈƱÍͤË) ¼ÂºÝ¤Ë¤Ï
255 .I int
256 ¤Ç¤¢¤ë¡£glibc ¤Ç¤â»È¤ï¤ì¤Æ¤¤¤ë¸½ºß¤Î
257 .I socklen_t
258 ¤Ë´Ø¤·¤Æ¡¢POSIX ¤Ë¤Ï¾¯¤·º®Í𤬤¢¤ë¡£
259 ¾Ü¤·¤¯¤Ï
260 .BR accept (2)
261 ¤ò»²¾È¤Î¤³¤È¡£
262 .SH ¥Ð¥°
263 Æ©²áŪ¥×¥í¥­¥· (transparent proxy) ¥ª¥×¥·¥ç¥ó¤Ë¤Ä¤¤¤Æµ­½Ò¤·¤Æ¤¤¤Ê¤¤¡£
264 .\" FIXME What *are* transparent proxy options?
265 .SH Îã
266 ¥¤¥ó¥¿¡¼¥Í¥Ã¥È¡¦¥É¥á¥¤¥ó¡¦¥½¥±¥Ã¥È¤Ç¤Î
267 .BR bind ()
268 ¤ÎÍøÍÑÎ㤬
269 .BR getaddrinfo (3)
270 ¤Ëµ­ºÜ¤µ¤ì¤Æ¤¤¤ë¡£
271
272 °Ê²¼¤ÎÎã¤Ï¡¢Unix ¥É¥á¥¤¥ó
273 .RB ( AF_UNIX )
274 ¤Ç¥¹¥È¥ê¡¼¥à¥½¥±¥Ã¥È¤ò bind ¤¹¤ëÊýË¡¤ò¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
275 .\" listen.7 refers to this example.
276 .\" accept.7 refers to this example.
277 .\" unix.7 refers to this example.
278
279 .nf
280 #include <sys/socket.h>
281 #include <sys/un.h>
282 #include <stdlib.h>
283 #include <stdio.h>
284 #include <string.h>
285
286 #define MY_SOCK_PATH "/somepath"
287 #define LISTEN_BACKLOG 50
288
289 #define handle_error(msg) \\
290     do { perror(msg); exit(EXIT_FAILURE); } while (0)
291
292 int
293 main(int argc, char *argv[])
294 {
295     int sfd, cfd;
296     struct sockaddr_un my_addr, peer_addr;
297     socklen_t peer_addr_size;
298
299     sfd = socket(AF_UNIX, SOCK_STREAM, 0);
300     if (sfd == \-1)
301         handle_error("socket");
302
303     memset(&my_addr, 0, sizeof(struct sockaddr_un));
304                         /* Clear structure */
305     my_addr.sun_family = AF_UNIX;
306     strncpy(my_addr.sun_path, MY_SOCK_PATH,
307             sizeof(my_addr.sun_path) \- 1);
308
309     if (bind(sfd, (struct sockaddr *) &my_addr,
310             sizeof(struct sockaddr_un)) == \-1)
311         handle_error("bind");
312     
313     if (listen(sfd, LISTEN_BACKLOG) == \-1)
314         handle_error("listen");
315
316     /* Now we can accept incoming connections one
317        at a time using accept(2) */
318
319     peer_addr_size = sizeof(struct sockaddr_un);
320     cfd = accept(sfd, (struct sockaddr *) &peer_addr,
321                  &peer_addr_size)
322     if (cfd == \-1)
323         handle_error("accept");
324
325     /* Code to deal with incoming connection(s)... */
326
327     /* When no longer required, the socket pathname, MY_SOCK_PATH
328        should be deleted using unlink(2) or remove(3) */
329 }
330 .fi
331 .SH ´ØÏ¢¹àÌÜ
332 .BR accept (2),
333 .BR connect (2),
334 .BR getsockname (2),
335 .BR listen (2),
336 .BR socket (2),
337 .BR getaddrinfo (3),
338 .BR getifaddrs (3),
339 .BR ip (7),
340 .BR ipv6 (7),
341 .BR path_resolution (7),
342 .BR socket (7),
343 .BR unix (7)