OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[linuxjm/LDP_man-pages.git] / draft / 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 .\"O .SH NAME
79 .SH Ì¾Á°
80 .\"O bind \- bind a name to a socket
81 bind \- ¥½¥±¥Ã¥È¤Ë̾Á°¤ò¤Ä¤±¤ë
82 .\"O .SH SYNOPSIS
83 .SH ½ñ¼°
84 .nf
85 .\"O .BR "#include <sys/types.h>" "          /* See NOTES */"
86 .BR "#include <sys/types.h>" "          /* ¡ÖÃí°Õ¡×»²¾È */"
87 .B #include <sys/socket.h>
88 .sp
89 .BI "int bind(int " sockfd ", const struct sockaddr *" addr ,
90 .BI "         socklen_t " addrlen );
91 .fi
92 .\"O .SH DESCRIPTION
93 .SH ÀâÌÀ
94 .\"O When a socket is created with
95 .\"O .BR socket (2),
96 .\"O it exists in a name space (address family) but has no address assigned to it.
97 .\"O .BR bind ()
98 .\"O assigns the address specified to by
99 .\"O .I addr
100 .\"O to the socket referred to by the file descriptor
101 .\"O .IR sockfd .
102 .\"O .I addrlen
103 .\"O specifies the size, in bytes, of the address structure pointed to by
104 .\"O .IR addr .
105 .\"O Traditionally, this operation is called \(lqassigning a name to a socket\(rq.
106 .BR socket (2)
107 ¤Ç¥½¥±¥Ã¥È¤¬ºîÀ®¤µ¤ì¤¿¤È¤­¡¢¤½¤Î¥½¥±¥Ã¥È¤Ï̾Á°¶õ´Ö (¥¢¥É¥ì¥¹¡¦¥Õ¥¡¥ß¥ê¡¼) ¤Ë
108 ¸ºß¤¹¤ë¤¬¡¢¥¢¥É¥ì¥¹¤Ï³ä¤êÅö¤Æ¤é¤ì¤Æ¤¤¤Ê¤¤¡£
109 .BR bind ()
110 ¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
111 .I sockfd
112 ¤Ç»²¾È¤µ¤ì¤ë¥½¥±¥Ã¥È¤Ë
113 .I addr
114 ¤Ç»ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¤ò³ä¤êÅö¤Æ¤ë¡£
115 .I addrlen
116 ¤Ë¤Ï
117 .I addr
118 ¤¬»Ø¤¹¥¢¥É¥ì¥¹¹½Â¤ÂΤΥµ¥¤¥º¤ò¥Ð¥¤¥Èñ°Ì¤Ç»ØÄꤹ¤ë¡£
119 ÅÁÅýŪ¤Ë¤³¤ÎÁàºî¤Ï
120 ¡Ö¥½¥±¥Ã¥È¤Ë̾Á°¤ò¤Ä¤±¤ë¡×
121 ¤È¸Æ¤Ð¤ì¤ë¡£
122 .PP
123 .\"O It is normally necessary to assign a local address using
124 .\"O .BR bind ()
125 .\"O before a
126 .\"O .B SOCK_STREAM
127 .\"O socket may receive connections (see
128 .\"O .BR accept (2)).
129 .B SOCK_STREAM
130 ¥½¥±¥Ã¥È¤¬Àܳ¤ò¼õ¤±ÉÕ¤±¤é¤ì¤ë¤è¤¦¤Ë¤¹¤ë¤Ë¤Ï
131 .RB ( accept (2)
132 ¤ò»²¾È)¡¢Ä̾綠¤ÎÁ°¤Ë
133 .BR bind ()
134 ¤ò»ÈÍѤ·¤Æ¥í¡¼¥«¥ë¥¢¥É¥ì¥¹¤ò³ä¤êÅö¤Æ¤ëɬÍפ¬¤¢¤ë¡£
135
136 .\"O The rules used in name binding vary between address families.
137 .\"O Consult the manual entries in Section 7 for detailed information.
138 .\"O For
139 .\"O .B AF_INET
140 .\"O see
141 .\"O .BR ip (7),
142 ̾Á°ÉÕ¤±¤Î¥ë¡¼¥ë¤Ï¥¢¥É¥ì¥¹¡¦¥Õ¥¡¥ß¥ê¡¼¤´¤È¤Ë°Û¤Ê¤Ã¤Æ¤¤¤ë¡£¾ÜºÙ¤Ê¾ðÊó¤Ï
143 Âè 7 ¾Ï¤Î³Æ¥Þ¥Ë¥å¥¢¥ë¤ò»²¾È¤¹¤ë¤³¤È¡£
144 .B AF_INET
145 ¤Ï
146 .BR ip (7)
147 ¤ò¡¢
148 .\"O for
149 .\"O .B AF_INET6
150 .\"O see
151 .\"O .BR ipv6 (7),
152 .B AF_INET6
153 ¤Ï
154 .BR ipv6 (7)
155 ¤ò¡¢
156 .\"O for
157 .\"O .B AF_UNIX
158 .\"O see
159 .\"O .BR unix (7),
160 .B AF_UNIX
161 ¤Ï
162 .BR unix (7)
163 ¤ò¡¢
164 .\"O for
165 .\"O .B AF_APPLETALK
166 .\"O see
167 .\"O .BR ddp (7),
168 .B AF_APPLETALK
169 ¤Ï
170 .BR ddp (7)
171 ¤ò¡¢
172 .\"O for
173 .\"O .B AF_PACKET
174 .\"O see
175 .\"O .BR packet (7),
176 .B AF_PACKET
177 ¤Ï
178 .BR packet (7)
179 ¤ò¡¢
180 .\"O for
181 .\"O .B AF_X25
182 .\"O see
183 .\"O .BR x25 (7)
184 .B AF_X25
185 ¤Ï
186 .BR x25 (7)
187 ¤ò¡¢
188 .\"O and for
189 .\"O .B AF_NETLINK
190 .\"O see
191 .\"O .BR netlink (7).
192 .B AF_NETLINK
193 ¤Ï
194 .BR netlink (7)
195 ¤ò»²¾È¡£
196
197 .\"O The actual structure passed for the
198 .\"O .I addr
199 .\"O argument will depend on the address family.
200 .\"O The
201 .\"O .I sockaddr
202 .\"O structure is defined as something like:
203 .I addr
204 °ú¤­¿ô¤Ë¼ÂºÝ¤Ë¤É¤Î¤è¤¦¤Ê¹½Â¤ÂΤ¬ÅϤµ¤ì¤ë¤«¤Ï¡¢
205 ¥¢¥É¥ì¥¹¡¦¥Õ¥¡¥ß¥ê¡¼¤Ë°Í¸¤¹¤ë¡£
206 .I sockaddr
207 ¹½Â¤ÂΤϰʲ¼¤Î¤è¤¦¤Ê´¶¤¸¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
208 .in +4n
209 .nf
210
211 struct sockaddr {
212     sa_family_t sa_family;
213     char        sa_data[14];
214 }
215
216 .fi
217 .in
218 .\"O The only purpose of this structure is to cast the structure
219 .\"O pointer passed in
220 .\"O .I addr
221 .\"O in order to avoid compiler warnings.
222 .\"O See EXAMPLE below.
223 ¤³¤Î¹½Â¤ÂΤϡ¢
224 .I addr
225 ¤ËÅϤµ¤ì¤ë¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤ò¥­¥ã¥¹¥È¤·¡¢
226 ¥³¥ó¥Ñ¥¤¥é¤Î·Ù¹ð¥á¥Ã¥»¡¼¥¸¤òÍÞ¤¨¤ë¤¿¤á¤À¤±¤Ë¸ºß¤¹¤ë¡£
227 ²¼µ­¤Î¡ÖÎã¡×¤ò»²¾È¡£
228 .\"O .SH "RETURN VALUE"
229 .SH ÊÖ¤êÃÍ
230 .\"O On success, zero is returned.
231 .\"O On error, \-1 is returned, and
232 .\"O .I errno
233 .\"O is set appropriately.
234 À®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤¹¡£
235 ¼ºÇÔ¤¹¤ë¤È \-1 ¤òÊÖ¤·¡¢
236 .I errno
237 ¤òŬÀÚ¤ËÀßÄꤹ¤ë¡£
238 .\"O .SH ERRORS
239 .SH ¥¨¥é¡¼
240 .TP
241 .B EACCES
242 .\" e.g., privileged port in AF_INET domain
243 .\"O The address is protected, and the user is not the superuser.
244 ¤½¤Î¥¢¥É¥ì¥¹¤ÏÊݸ¤ì¤Æ¤¤¤Æ¡¢¤«¤Ä¥æ¡¼¥¶¤¬¥¹¡¼¥Ñ¡¼¥æ¡¼¥¶¤Ç¤Ï¤Ê¤¤¡£
245 .TP
246 .B EADDRINUSE
247 .\"O The given address is already in use.
248 »ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¤¬´û¤Ë»ÈÍÑÃæ¤Ç¤¢¤ë¡£
249 .TP
250 .B EBADF
251 .\"O .I sockfd
252 .\"O is not a valid descriptor.
253 .I sockfd
254 ¤¬ÉÔÀµ¤Ê¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤¢¤ë¡£
255 .TP
256 .B EINVAL
257 .\"O The socket is already bound to an address.
258 .\"O .\" This may change in the future: see
259 .\"O .\" .I linux/unix/sock.c for details.
260 ¥½¥±¥Ã¥È¤¬¤¹¤Ç¤Ë¥¢¥É¥ì¥¹¤Ë·ë¤Ó¤Ä¤± (bind) ¤é¤ì¤Æ¤¤¤ë¡£
261 .\" ¤³¤ì¤Ï¾­ÍèÊѹ¹¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
262 .\" ¾Ü¤·¤¯¤Ï
263 .\" .I linux/unix/sock.c
264 .\" ¤ò»²¾È¤¹¤ë¤³¤È¡£
265 .B ENOTSOCK
266 .\"O .I sockfd
267 .\"O is a descriptor for a file, not a socket.
268 .I sockfd
269 ¤¬¥Õ¥¡¥¤¥ë¤ËÂФ¹¤ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¡¢¥½¥±¥Ã¥È¤ËÂФ¹¤ë¤â¤Î¤Ç¤Ï¤Ê¤¤¡£
270 .PP
271 .\"O The following errors are specific to Unix domain
272 .\"O .RB ( AF_UNIX )
273 .\"O sockets:
274 °Ê²¼¤Î¥¨¥é¡¼¤Ï Unix¥É¥á¥¤¥ó
275 .RB ( AF_UNIX )
276 ¤Î¥½¥±¥Ã¥ÈÆÃÍ­¤Ç¤¢¤ë:
277 .TP
278 .B EACCES
279 .\"O Search permission is denied on a component of the path prefix.
280 .\"O (See also
281 .\"O .BR path_resolution (7).)
282 ¥Ñ¥¹Ì¾¤Î¹½À®Í×ÁǤ˸¡º÷µö²Ä (search permission) ¤¬¤Ê¤¤
283 .RB ( path_resolution (7)
284 ¤â»²¾È¤¹¤ë¤³¤È)¡£
285 .TP
286 .B EADDRNOTAVAIL
287 .\"O A nonexistent interface was requested or the requested
288 .\"O address was not local.
289 ¸ºß¤·¤Ê¤¤¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤¬Í׵ᤵ¤ì¤¿¤«¡¢Í׵ᤵ¤ì¤¿¥¢¥É¥ì¥¹¤¬
290 ¥í¡¼¥«¥ë¤Ç¤Ï¤Ê¤«¤Ã¤¿¡£
291 .TP
292 .B EFAULT
293 .\"O .I addr
294 .\"O points outside the user's accessible address space.
295 .I addr
296 ¤¬¥æ¡¼¥¶¤Î¥¢¥¯¥»¥¹²Äǽ¤Ê¥¢¥É¥ì¥¹¶õ´Ö¤Î³°¤ò»Ø¤·¤Æ¤¤¤ë¡£
297 .TP
298 .B EINVAL
299 .\"O The
300 .\"O .I addrlen
301 .\"O is wrong, or the socket was not in the
302 .\"O .B AF_UNIX
303 .\"O family.
304 .I addrlen
305 ¤¬ÉÔÀµ¤Ç¤¢¤ë¤«¡¢¥½¥±¥Ã¥È¤¬
306 .B AF_UNIX
307 ¥Õ¥¡¥ß¥ê¡¼¤Ç¤Ï¤Ê¤¤¡£
308 .TP
309 .B ELOOP
310 .\"O Too many symbolic links were encountered in resolving
311 .\"O .IR addr .
312 .I addr
313 ¤ò²ò·è¤¹¤ëºÝ¤ËÁø¶ø¤·¤¿¥·¥ó¥Ü¥ê¥Ã¥¯¡¦¥ê¥ó¥¯¤¬Â¿²á¤®¤ë¡£
314 .TP
315 .B ENAMETOOLONG
316 .\"O .I addr
317 .\"O is too long.
318 .I addr
319 ¤¬Ä¹²á¤®¤ë¡£
320 .TP
321 .B ENOENT
322 .\"O The file does not exist.
323 ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤¤¡£
324 .TP
325 .B ENOMEM
326 .\"O Insufficient kernel memory was available.
327 ¥«¡¼¥Í¥ë¤Ë¡¢ÍøÍѲÄǽ¤Ê¥á¥â¥ê¡¼¤¬½½Ê¬¤Ë¤Ê¤¤¡£
328 .TP
329 .B ENOTDIR
330 .\"O A component of the path prefix is not a directory.
331 ¥Ñ¥¹Ì¾¤Î¹½À®Í×ÁǤ¬¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤Ï¤Ê¤¤¡£
332 .TP
333 .B EROFS
334 .\"O The socket inode would reside on a read-only file system.
335 ¥½¥±¥Ã¥È inode ¤¬Æɤ߹þ¤ßÀìÍѤΥե¡¥¤¥ë¥·¥¹¥Æ¥à¾å¤Ë¤¢¤ë¡£
336 .\"O .SH "CONFORMING TO"
337 .SH ½àµò
338 .\"O SVr4, 4.4BSD, POSIX.1-2001
339 .\"O .RB ( bind ()
340 .\"O first appeared in 4.2BSD).
341 .\"O .\" SVr4 documents an additional
342 .\"O .\" .B ENOSR
343 .\"O .\" general error condition, and
344 .\"O .\" additional
345 .\"O .\" .B EIO
346 .\"O .\" and
347 .\"O .\" .B EISDIR
348 .\"O .\" Unix-domain error conditions.
349 SVr4, 4.4BSD, POSIX.1-2001
350 .RB ( bind ()
351 ¤Ï 4.2BSD ¤ÇºÇ½é¤Ë¸½¤ï¤ì¤¿)¡£
352 .\" SVr4 ¤Ë¤Ï¾¤Ë¡¢°ìÈ̤Υ¨¥é¡¼¾õÂÖ
353 .\" .B ENOSR
354 .\" µÚ¤Ó Unix ¥É¥á¥¤¥ó¤Î¥¨¥é¡¼¾õÂÖ
355 .\" .BR EIO ,
356 .\" .B EISDIR
357 .\" ¤Ë¤Ä¤¤¤Æ¤Îµ­½Ò¤¬¤¢¤ë¡£
358 .\"O .SH NOTES
359 .SH Ãí°Õ
360 .\"O POSIX.1-2001 does not require the inclusion of
361 .\"O .IR <sys/types.h> ,
362 .\"O and this header file is not required on Linux.
363 .\"O However, some historical (BSD) implementations required this header
364 .\"O file, and portable applications are probably wise to include it.
365 POSIX.1-2001 ¤Ç¤Ï
366 .I <sys/types.h>
367 ¤Î¥¤¥ó¥¯¥ë¡¼¥É¤Ïɬ¿Ü¤È¤µ¤ì¤Æ¤ª¤é¤º¡¢
368 Linux ¤Ç¤Ï¤³¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤ÏɬÍפǤϤʤ¤¡£
369 ¤·¤«¤·¡¢Îò»ËŪ¤Ë¤Ï¡¢¤¤¤¯¤Ä¤«¤Î¼ÂÁõ (BSD ·Ï) ¤Ç¤³¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤¬
370 ɬÍפǤ¢¤ê¡¢°Ü¿¢À­¤¬É¬Íפʥ¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¤³¤Î¥Õ¥¡¥¤¥ë¤ò
371 ¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤Î¤¬¸­ÌÀ¤Ç¤¢¤í¤¦¡£
372
373 .\"O The third argument of
374 .\"O .BR bind ()
375 .\"O is in reality an
376 .\"O .I int
377 .\"O (and this is what 4.x BSD and libc4 and libc5 have).
378 .\"O Some POSIX confusion resulted in the present
379 .\"O .IR socklen_t ,
380 .\"O also used by glibc.
381 .\"O See also
382 .\"O .BR accept (2).
383 .BR bind ()
384 ¤Î»°ÈÖÌܤΰú¤­¿ô¤Ï (4.x BSD ¤ä libc4, libc5 ¤ÈƱÍͤË) ¼ÂºÝ¤Ë¤Ï
385 .I int
386 ¤Ç¤¢¤ë¡£glibc ¤Ç¤â»È¤ï¤ì¤Æ¤¤¤ë¸½ºß¤Î
387 .I socklen_t
388 ¤Ë´Ø¤·¤Æ¡¢POSIX ¤Ë¤Ï¾¯¤·º®Í𤬤¢¤ë¡£
389 ¾Ü¤·¤¯¤Ï
390 .BR accept (2)
391 ¤ò»²¾È¤Î¤³¤È¡£
392 .\"O .SH BUGS
393 .SH ¥Ð¥°
394 .\"O The transparent proxy options are not described.
395 Æ©²áŪ¥×¥í¥­¥· (transparent proxy) ¥ª¥×¥·¥ç¥ó¤Ë¤Ä¤¤¤Æµ­½Ò¤·¤Æ¤¤¤Ê¤¤¡£
396 .\" FIXME What *are* transparent proxy options?
397 .\"O .SH EXAMPLE
398 .SH Îã
399 .\"O An example of the use of
400 .\"O .BR bind ()
401 .\"O with Internet domain sockets can be found in
402 .\"O .BR getaddrinfo (3).
403 ¥¤¥ó¥¿¡¼¥Í¥Ã¥È¡¦¥É¥á¥¤¥ó¡¦¥½¥±¥Ã¥È¤Ç¤Î
404 .BR bind ()
405 ¤ÎÍøÍÑÎ㤬
406 .BR getaddrinfo (3)
407 ¤Ëµ­ºÜ¤µ¤ì¤Æ¤¤¤ë¡£
408
409 .\"O The following example shows how to bind a stream socket in the Unix
410 .\"O .RB ( AF_UNIX )
411 .\"O domain, and accept connections:
412 °Ê²¼¤ÎÎã¤Ï¡¢Unix ¥É¥á¥¤¥ó
413 .RB ( AF_UNIX )
414 ¤Ç¥¹¥È¥ê¡¼¥à¥½¥±¥Ã¥È¤ò bind ¤¹¤ëÊýË¡¤ò¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
415 .\" listen.7 refers to this example.
416 .\" accept.7 refers to this example.
417 .\" unix.7 refers to this example.
418
419 .nf
420 #include <sys/socket.h>
421 #include <sys/un.h>
422 #include <stdlib.h>
423 #include <stdio.h>
424 #include <string.h>
425
426 #define MY_SOCK_PATH "/somepath"
427 #define LISTEN_BACKLOG 50
428
429 #define handle_error(msg) \\
430     do { perror(msg); exit(EXIT_FAILURE); } while (0)
431
432 int
433 main(int argc, char *argv[])
434 {
435     int sfd, cfd;
436     struct sockaddr_un my_addr, peer_addr;
437     socklen_t peer_addr_size;
438
439     sfd = socket(AF_UNIX, SOCK_STREAM, 0);
440     if (sfd == \-1)
441         handle_error("socket");
442
443     memset(&my_addr, 0, sizeof(struct sockaddr_un));
444                         /* Clear structure */
445     my_addr.sun_family = AF_UNIX;
446     strncpy(my_addr.sun_path, MY_SOCK_PATH,
447             sizeof(my_addr.sun_path) \- 1);
448
449     if (bind(sfd, (struct sockaddr *) &my_addr,
450             sizeof(struct sockaddr_un)) == \-1)
451         handle_error("bind");
452     
453     if (listen(sfd, LISTEN_BACKLOG) == \-1)
454         handle_error("listen");
455
456     /* Now we can accept incoming connections one
457        at a time using accept(2) */
458
459     peer_addr_size = sizeof(struct sockaddr_un);
460     cfd = accept(sfd, (struct sockaddr *) &peer_addr,
461                  &peer_addr_size)
462     if (cfd == \-1)
463         handle_error("accept");
464
465     /* Code to deal with incoming connection(s)... */
466
467     /* When no longer required, the socket pathname, MY_SOCK_PATH
468        should be deleted using unlink(2) or remove(3) */
469 }
470 .fi
471 .\"O .SH "SEE ALSO"
472 .SH ´ØÏ¢¹àÌÜ
473 .BR accept (2),
474 .BR connect (2),
475 .BR getsockname (2),
476 .BR listen (2),
477 .BR socket (2),
478 .BR getaddrinfo (3),
479 .BR getifaddrs (3),
480 .BR ip (7),
481 .BR ipv6 (7),
482 .BR path_resolution (7),
483 .BR socket (7),
484 .BR unix (7)