1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" $Id: getsockopt.2,v 1.1 1999/05/24 14:57:04 freitag Exp $
34 .\" Modified Sat Jul 24 16:19:32 1993 by Rik Faith (faith@cs.unc.edu)
35 .\" Modified Mon Apr 22 02:29:06 1996 by Martin Schulze (joey@infodrom.north.de)
36 .\" Modified Tue Aug 27 10:52:51 1996 by Andries Brouwer (aeb@cwi.nl)
37 .\" Modified Thu Jan 23 13:29:34 1997 by Andries Brouwer (aeb@cwi.nl)
38 .\" Modified Sun Mar 28 21:26:46 1999 by Andries Brouwer (aeb@cwi.nl)
39 .\" Modified 1999 by Andi Kleen <ak@muc.de>.
40 .\" Removed most stuff because it is in socket.7 now.
42 .\" Japanese Version Copyright (c) 1996 Akira Yoshiyama
43 .\" all rights reserved.
44 .\" Translated Sat Jul 6 00:43:37 JST 1996
45 .\" by Akira Yoshiyama <yosshy@jedi.seg.kobe-u.ac.jp>
46 .\" Modified Fri Nov 7 22:45:27 JST 1997
47 .\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
48 .\" Updated Sun Oct 12 JST 2003 by Kentaro Shirakata <argrath@ub32.org>
50 .TH GETSOCKOPT 2 2008-12-03 "Linux" "Linux Programmer's Manual"
53 .\"O getsockopt, setsockopt \- get and set options on sockets
54 getsockopt, setsockopt \- ¥½¥±¥Ã¥È¤Î¥ª¥×¥·¥ç¥ó¤ÎÀßÄê¤È¼èÆÀ¤ò¹Ô¤Ê¤¦
58 .\"O .BR "#include <sys/types.h>" " /* See NOTES */"
59 .BR "#include <sys/types.h>" " /* ¡ÖÃí°Õ¡×»²¾È */"
61 .B #include <sys/socket.h>
63 .BI "int getsockopt(int " sockfd ", int " level ", int " optname ,
64 .BI " void *" optval ", socklen_t *" optlen );
65 .BI "int setsockopt(int " sockfd ", int " level ", int " optname ,
66 .BI " const void *" optval ", socklen_t " optlen );
70 .\"O .BR getsockopt ()
72 .\"O .BR setsockopt ()
73 .\"O manipulate options for the socket referred to by the file descriptor
75 .\"O Options may exist at multiple
76 .\"O protocol levels; they are always present at the uppermost
81 ¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
83 ¤Ç»²¾È¤µ¤ì¤ë¥½¥±¥Ã¥È¤Ë´ØÏ¢¤¹¤ë¥ª¥×¥·¥ç¥ó¤ÎÁàºî¤ò¹Ô¤¦¡£
84 ¥ª¥×¥·¥ç¥ó¤ÏÊ£¿ô¤Î¥×¥í¥È¥³¥ëÁØ(level)¤Ë¸ºß¤¹¤ë¤«¤â¤·¤ì¤Ê¤¤¤¬¡¢
85 ¤³¤ì¤é¤Ï¾ï¤ËºÇ¾å°Ì¤Î¥½¥±¥Ã¥ÈÁؤؤÈÀßÄꤵ¤ì¤ë¡£
87 .\"O When manipulating socket options, the level at which the
88 .\"O option resides and the name of the option must be specified.
89 .\"O To manipulate options at the sockets API level,
93 .\"O To manipulate options at any
94 .\"O other level the protocol number of the appropriate protocol
95 .\"O controlling the option is supplied.
97 .\"O to indicate that an option is to be interpreted by the
101 .\"O should be set to the protocol number of
104 .\"O .BR getprotoent (3).
105 ¥½¥±¥Ã¥È¡¦¥ª¥×¥·¥ç¥ó¤òÁàºî¤¹¤ëºÝ¤Ë¤Ï¡¢¥ª¥×¥·¥ç¥ó¤ÎÁØ (level) ¤È
106 ¥ª¥×¥·¥ç¥ó¤Î̾Á°¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
107 ¥½¥±¥Ã¥È API Áؤǥª¥×¥·¥ç¥ó¤òÁàºî¤¹¤ë°Ù¤Ë¤Ï¡¢
112 ¾¤ÎÁ´¤Æ¤ÎÁؤǥª¥×¥·¥ç¥ó¤òÁàºî¤¹¤ë°Ù¤Ë¤Ï¡¢Í¿¤¨¤é¤ì¤¿¥ª¥×¥·¥ç¥ó¤Î
113 À©¸æ¼çÂΤȤʤë¥×¥í¥È¥³¥ë¤Î¥×¥í¥È¥³¥ëÈÖ¹æ¤ò»ØÄꤹ¤ë¡£Î㤨¤Ð¡¢
116 ¥×¥í¥È¥³¥ë¤Ç²ò¼á¤µ¤ì¤ë¤Ù¤¤³¤È¤ò»Ø¼¨¤¹¤ë¤Ë¤Ï¡¢
120 ¤Î¥×¥í¥È¥³¥ëÈÖ¹æ¤ò»ØÄꤷ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
128 .\"O are used to access option values for
129 .\"O .BR setsockopt ().
135 ¤Î¥ª¥×¥·¥ç¥ó¤ÎÃͤ˥¢¥¯¥»¥¹¤¹¤ë¤¿¤á¤ËÍѤ¤¤é¤ì¤ë¡£
137 .\"O .BR getsockopt ()
138 .\"O they identify a buffer in which the value for the
139 .\"O requested option(s) are to be returned.
141 ¤Ç¤ÏÍ׵ᤷ¤¿¥ª¥×¥·¥ç¥ó¤ÎÃͤòÊÖ¤¹¤¿¤á¤Î¥Ð¥Ã¥Õ¥¡¡¼¤ò»ØÄꤹ¤ë¡£
143 .\"O .BR getsockopt (),
145 .\"O is a value-result argument, initially containing the
146 .\"O size of the buffer pointed to by
148 .\"O and modified on return to indicate the actual size of
149 .\"O the value returned.
150 .\"O If no option value is to be supplied or returned,
156 ¤ÏÃͤȷë²ÌξÍѤΰú¤¿ô¤Ç¡¢ºÇ½é¤Ë
158 ¤Î»Ø¤·¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡¡¼¤Î¥µ¥¤¥º¤òÍ¿¤¨¡¢¼ÂºÝ¤ËÊÖ¤µ¤ì¤ëÃͤΥµ¥¤¥º¤Ë
159 ½ñ¤´¹¤¨¤é¤ì¤ë¡£¤â¤·¥ª¥×¥·¥ç¥óÃͤòÍ¿¤¨¤º¡¢ÊÖ¤µ¤ì¤â¤·¤Ê¤¤¾ì¹ç¤Ë¤Ï
164 .\"O and any specified options are passed uninterpreted to the appropriate
165 .\"O protocol module for interpretation.
166 .\"O The include file
167 .\"O .I <sys/socket.h>
168 .\"O contains definitions for socket level options, described below.
170 .\"O other protocol levels vary in format and name; consult the appropriate
171 .\"O entries in section 4 of the manual.
173 ¤ª¤è¤Ó»ØÄꤵ¤ì¤¿¥ª¥×¥·¥ç¥ó¤Ï²ò¼á¤µ¤ì¤º¤Ë¡¢Å¬Àڤʥץí¥È¥³¥ë¡¦¥â¥¸¥å¡¼¥ë¤Ë
174 ÅϤµ¤ì¤Æ²ò¼á¤µ¤ì¤ë¡£¥¤¥ó¥¯¥ë¡¼¥É¡¦¥Õ¥¡¥¤¥ë
176 ¤Ë¤Ï¸å½Ò¤Î¥½¥±¥Ã¥ÈÁؤΥª¥×¥·¥ç¥ó¤ÎÄêµÁ¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¡£
177 ¾¤Î¥×¥í¥È¥³¥ëÁؤǤÏ̾Á°¤ä·Á¼°¤Ï°Û¤Ê¤ë¡£
178 ¥Þ¥Ë¥å¥¢¥ë¤Î¥»¥¯¥·¥ç¥ó 4 ¤ÎŬÀڤʥ¨¥ó¥È¥ê¤ò»²¾È¤¹¤ë¤³¤È¡£
180 .\"O Most socket-level options utilize an
185 .\"O .BR setsockopt (),
186 .\"O the argument should be nonzero to enable a boolean option, or zero if the
187 .\"O option is to be disabled.
188 ¤Û¤È¤ó¤É¤Î¥½¥±¥Ã¥ÈÁؤΥª¥×¥·¥ç¥ó¤Ï
194 ¤Ç¡¢ÆóÃÍ(boolean)¥ª¥×¥·¥ç¥ó¤ò͸ú(enable)¤Ë¤¹¤ë¤Ë¤Ï¥¼¥í°Ê³°¤ò»ØÄꤷ¡¢
195 ̵¸ú(disable)¤Ë¤¹¤ë¤Ë¤Ï¥¼¥í¤ò»ØÄꤹ¤ë¡£
197 .\"O For a description of the available socket options see
199 .\"O and the appropriate protocol man pages.
200 ÍøÍѲÄǽ¤Ê¥½¥±¥Ã¥È¥ª¥×¥·¥ç¥ó¤ÎÀâÌÀ¤Ë´Ø¤·¤Æ¤Ï¡¢
202 ¤ÈŬÀڤʥץí¥È¥³¥ë¤Î man ¥Ú¡¼¥¸¤ò»²¾È¤Î¤³¤È¡£
203 .\"O .SH "RETURN VALUE"
205 .\"O On success, zero is returned.
206 .\"O On error, \-1 is returned, and
208 .\"O is set appropriately.
209 À®¸ù¤·¤¿¾ì¹ç¤Ë¤Ï¥¼¥í¤òÊÖ¤¹¡£¥¨¥é¡¼»þ¤Ë¤Ï \-1 ¤¬ÊÖ¤µ¤ì¡¢
218 .\"O is not a valid descriptor.
221 ¤¬Í¸ú¤Ê¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¡£
224 .\"O The address pointed to by
226 .\"O is not in a valid part of the process address space.
228 .\"O .BR getsockopt (),
229 .\"O this error may also be returned if
231 .\"O is not in a valid part of the process address space.
233 ¤Ç»ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¤¬¥×¥í¥»¥¹¤Î¥¢¥É¥ì¥¹¶õ´Ö¤Î͸ú¤ÊÉôʬ¤Ç¤Ï¤Ê¤¤¡£
237 ¤¬¥×¥í¥»¥¹¤Î¥¢¥É¥ì¥¹¶õ´Ö¤Î͸ú¤ÊÉôʬ¤Ç¤Ê¤¤¾ì¹ç¤Ë¤â¤³¤Î¥¨¥é¡¼¤¬ÊÖ¤µ¤ì¤ë¡£
242 .\"O .BR setsockopt ().
247 .\"O In some cases this error can also occur for an invalid value in
250 .\"O .B IP_ADD_MEMBERSHIP
251 .\"O option described in
254 ¤Ë̵¸ú¤ÊÃͤ¬»ØÄꤵ¤ì¤¿¾ì¹ç¤Ë¤â¡¢¤³¤Î¥¨¥é¡¼¤¬È¯À¸¤¹¤ë²ÄǽÀ¤¬¤¢¤ë
262 .\"O The option is unknown at the level indicated.
263 »ØÄꤵ¤ì¤¿ÁØ(level)¤Ë¤Ï¤³¤Î¥ª¥×¥·¥ç¥ó¤Ï¸ºß¤·¤Ê¤¤¡£
268 .\"O is a file, not a socket.
271 ¤Ï¥Õ¥¡¥¤¥ë¤Ç¤¢¤ê¡¢¥½¥±¥Ã¥È¤Ç¤Ê¤¤¡£
272 .\"O .SH "CONFORMING TO"
274 .\"O SVr4, 4.4BSD (these system calls first appeared in 4.2BSD),
276 .\"O .\" SVr4 documents additional ENOMEM and ENOSR error codes, but does
277 .\"O .\" not document the
278 .\"O .\" .BR SO_SNDLOWAT ", " SO_RCVLOWAT ", " SO_SNDTIMEO ", " SO_RCVTIMEO
280 SVr4, 4.4BSD (¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¡¦¥³¡¼¥ë¤Ï 4.2BSD ¤ÇºÇ½é¤Ë¸½¤ì¤¿),
282 .\" SVr4 ¤Ë¤Ï¾¤Ë ENOMEM ¤È ENOSR ¥¨¥é¡¼¡¦¥³¡¼¥É¤Ë¤Ä¤¤¤Æ¤âµ½Ò¤µ¤ì¤Æ¤¤¤ë¡£
284 .\" .BR SO_SNDLOWAT ", " SO_RCVLOWAT ", " SO_SNDTIMEO ", " SO_RCVTIMEO
285 .\" ¥ª¥×¥·¥ç¥ó¤Ë´Ø¤¹¤ëµ½Ò¤Ï¤Ê¤¤¡£
288 .\"O POSIX.1-2001 does not require the inclusion of
289 .\"O .IR <sys/types.h> ,
290 .\"O and this header file is not required on Linux.
291 .\"O However, some historical (BSD) implementations required this header
292 .\"O file, and portable applications are probably wise to include it.
295 ¤Î¥¤¥ó¥¯¥ë¡¼¥É¤Ïɬ¿Ü¤È¤µ¤ì¤Æ¤ª¤é¤º¡¢
296 Linux ¤Ç¤Ï¤³¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤ÏɬÍפǤϤʤ¤¡£
297 ¤·¤«¤·¡¢Îò»ËŪ¤Ë¤Ï¡¢¤¤¤¯¤Ä¤«¤Î¼ÂÁõ (BSD ·Ï) ¤Ç¤³¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤¬
298 ɬÍפǤ¢¤ê¡¢°Ü¿¢À¤¬É¬Íפʥ¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¤³¤Î¥Õ¥¡¥¤¥ë¤ò
299 ¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤Î¤¬¸ÌÀ¤Ç¤¢¤í¤¦¡£
304 .\"O .BR getsockopt ()
306 .\"O .BR setsockopt ()
307 .\"O is in reality an
309 .\"O (and this is what 4.x BSD and libc4 and libc5 have).
317 ¤Ç¤¢¤ë (¤½¤·¤Æ 4.x BSD ¤È libc4 ¤È libc5 ¤Ï¤½¤¦¤Ê¤Ã¤Æ¤¤¤ë)¡£
318 .\"O Some POSIX confusion resulted in the present
320 .\"O also used by glibc.
322 POSIX ¤Ç¤Ïäþ;¶ÊÀÞ¤ò·Ð¤Æ¸½ºß¤Î
332 .\"O Several of the socket options should be handled at lower levels of the
334 ¥½¥±¥Ã¥È¤Î¥ª¥×¥·¥ç¥ó¤Î¤¤¤¯¤Ä¤«¤Ï¥·¥¹¥Æ¥à¤Î¤è¤êÄ㤤ÁؤÇ
335 ½èÍý¤µ¤ì¤ë¤Ù¤¤Ç¤¢¤ë¡£