OSDN Git Service

888fe0e4ffbeaf3007cfd553e1274f72a95525c1
[linuxjm/LDP_man-pages.git] / draft / man2 / gethostname.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
4 .\"
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\" Modified 1995-07-22 by Michael Chastain <mec@duracef.shout.net>:
27 .\"   'gethostname' is real system call on Linux/Alpha.
28 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
29 .\" Modified 2000-06-04, 2001-12-15 by aeb
30 .\" Modified 2004-06-17 by mtk
31 .\" Modified 2008-11-27 by mtk
32 .\"
33 .\" Japanese Version Copyright (c) 1997 SUTO, Mitsuaki
34 .\"         all rights reserved.
35 .\" Translated 1997-06-27, SUTO, Mitsuaki <suto@av.crl.sony.co.jp>
36 .\" Updated 2000-09-30, Yuichi SATO <sato@complex.eng.hokudai.ac.jp>
37 .\" Updated & Modified 2002-01-14, Yuichi SATO <ysato@h4.dion.ne.jp>
38 .\" Updated & Modified 2004-12-30, Yuichi SATO <ysato444@yahoo.co.jp>
39 .\" Updated & Modified 2006-01-31, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
40 .\" Updated 2008-12-26, Akihiro MOTOKI, LDP v3.15
41 .\"
42 .TH GETHOSTNAME 2 2010-09-26 "Linux" "Linux Programmer's Manual"
43 .\"O .SH NAME
44 .SH Ì¾Á°
45 .\"O gethostname, sethostname \- get/set hostname
46 gethostname, sethostname \- ¥Û¥¹¥È̾¤Î¼èÆÀ¡¦ÀßÄê¤ò¤¹¤ë
47 .\"O .SH SYNOPSIS
48 .SH ½ñ¼°
49 .B #include <unistd.h>
50 .sp
51 .BI "int gethostname(char *" name ", size_t " len );
52 .br
53 .BI "int sethostname(const char *" name ", size_t " len );
54 .sp
55 .in -4n
56 .\"O Feature Test Macro Requirements for glibc (see
57 .\"O .BR feature_test_macros (7)):
58 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
59 .RB ( feature_test_macros (7)
60 »²¾È):
61 .in
62 .sp
63 .ad l
64 .PD 0
65 .BR gethostname ():
66 .RS 4
67 .\"O Since glibc 2.12:
68 glibc 2.12 °Ê¹ß:
69 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
70 .br
71 .\"O || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200112L
72 || /* glibc 2.12 °Ê¹ß: */ _POSIX_C_SOURCE\ >=\ 200112L
73 .RE
74 .br
75 .BR sethostname ():
76 .RS 4
77 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
78 .RE
79 .PD
80 .ad
81 .\"O .SH DESCRIPTION
82 .SH ÀâÌÀ
83 .\"O These system calls are used to access or to change the hostname of the
84 .\"O current processor.
85 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢¸½ºß¤Î¥×¥í¥»¥Ã¥µ¤Î¥Û¥¹¥È̾¤ò¼èÆÀ¡¦Êѹ¹¤¹¤ë¤¿¤á¤Ë
86 »ÈÍѤµ¤ì¤ë¡£
87
88 .\"O .BR sethostname ()
89 .\"O sets the hostname to the value given in the character array
90 .\"O .IR name .
91 .\"O The
92 .\"O .I len
93 .\"O argument specifies the number of bytes in
94 .\"O .IR name .
95 .\"O (Thus,
96 .\"O .I name
97 .\"O does not require a terminating null byte.)
98 .BR sethostname ()
99 ¤Ï¡¢¥Û¥¹¥È̾¤ò¡¢Ê¸»úÇÛÎó
100 .I name
101 ¤Ç»ØÄꤵ¤ì¤¿ÃͤËÀßÄꤹ¤ë¡£
102 °ú¤­¿ô
103 .I len
104 ¤Ë¤Ï¡¢
105 .I name
106 ¤Î¥Ð¥¤¥È¿ô¤ò»ØÄꤹ¤ë
107 (¤½¤Î¤¿¤á¡¢
108 .I name
109 ¤Ç¤Ïʸ»úÎó½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤ÏɬÍפʤ¤)¡£
110
111 .\"O .BR gethostname ()
112 .\"O returns the null-terminated hostname in the character array
113 .\"O .IR name ,
114 .\"O which has a length of
115 .\"O .I len
116 .\"O bytes.
117 .\"O If the null-terminated hostname is too large to fit,
118 .\"O then the name is truncated, and no error is returned (but see NOTES below).
119 .\"O POSIX.1-2001 says that if such truncation occurs,
120 .\"O then it is unspecified whether the returned buffer
121 .\"O includes a terminating null byte.
122 .BR gethostname ()
123 ¤Ï¡¢NULL ½ªÃ¼¤µ¤ì¤¿¥Û¥¹¥È̾¤ò¡¢
124 .I len
125 ¥Ð¥¤¥È¤ÎŤµ¤Îʸ»úÇÛÎó
126 .I name
127 ¤Ë³ÊǼ¤·¤ÆÊÖ¤¹¡£
128 NULL ½ªÃ¼¤µ¤ì¤¿¥Û¥¹¥È̾¤¬³ÊǼÀè¤Î¥Ð¥Ã¥Õ¥¡¤è¤ê¤âŤ¤¾ì¹ç¤Ï¡¢
129 ¥Û¥¹¥È̾¤ÏÀÚ¤êµÍ¤á¤é¤ì¡¢¥¨¥é¡¼¤ÏÊÖ¤µ¤ì¤Ê¤¤ (²¼µ­¤Î¡ÖÃí°Õ¡×¤ÎÀá¤ò»²¾È)¡£
130 POSIX.1-2001 ¤Ç¤Ï¡¢·ë²Ì¤ÎÀÚ¤êµÍ¤á¤¬È¯À¸¤·¤¿¾ì¹ç¤Ë¡¢
131 ÊÖ¤µ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤Ë½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤Ï
132 µ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
133 .\"O .SH "RETURN VALUE"
134 .SH ÊÖ¤êÃÍ
135 .\"O On success, zero is returned.
136 .\"O On error, \-1 is returned, and
137 .\"O .I errno
138 .\"O is set appropriately.
139 À®¸ù¤·¤¿¾ì¹ç 0 ¤¬Ê֤롣¼ºÇÔ¤·¤¿¾ì¹ç \-1 ¤¬Ê֤ꡢ
140 .I errno
141 ¤¬¥¨¥é¡¼¤ÎÆâÍƤ˽¾¤Ã¤ÆÀßÄꤵ¤ì¤ë¡£
142 .\"O .SH ERRORS
143 .SH ¥¨¥é¡¼
144 .TP
145 .B EFAULT
146 .\"O .I name
147 .\"O is an invalid address.
148 .I name
149 ¤¬ÉÔÀµ¤Ê¥¢¥É¥ì¥¹¤Ç¤¢¤ë¡£
150 .TP
151 .B EINVAL
152 .\"O .I len
153 .\"O is negative
154 .\"O .\" Can't occur for gethostbyname() wrapper, since 'len' has an
155 .\"O .\" unsigned type; can occur for the underlying system call.
156 .\"O or, for
157 .\"O .BR sethostname (),
158 .\"O .I len
159 .\"O is larger than the maximum allowed size.
160 .I len
161 ¤¬Éé¤Ç¤¢¤ë¡£
162 .\" gethostbyname() ¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ç¤Ï¡¢'len' ¤Ï unsigned ·¿¤Ê¤Î¤Ç
163 .\" ¤³¤Î¥¨¥é¡¼¤¬È¯À¸¤¹¤ë¤³¤È¤Ï¤Ê¤¤¡£
164 .\" ¤½¤ÎÃæ¤Ç¸Æ¤Ð¤ì¤ë¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ç¤ÏȯÀ¸¤¹¤ë¤³¤È¤¬¤¢¤ë¡£
165 .BR sethostname ()
166 ¤Ë¤ª¤¤¤Æ
167 .I len
168 ¤¬µöÍƤµ¤ì¤¿ºÇÂ祵¥¤¥º¤ò±Û¤¨¤Æ¤¤¤ë¡£
169 .TP
170 .B ENAMETOOLONG
171 .\"O .RB "(glibc " gethostname ())
172 .\"O .I len
173 .\"O is smaller than the actual size.
174 .\"O (Before version 2.1, glibc uses
175 .\"O .BR EINVAL
176 .\"O for this case.)
177 .RB "(glibc " gethostname ()
178 ¤Ç)
179 .I len
180 ¤¬¼ÂºÝ¤Î¥Û¥¹¥È̾¤ÎŤµ¤è¤ê¤â¾®¤µ¤¤
181 (glibc ¥Ð¡¼¥¸¥ç¥ó 2.1 ¤è¤êÁ°¤Ç¤Ï¡¢¤³¤Î¾õ¶·¤Ç
182 .B EINVAL
183 ¤¬»ÈÍѤµ¤ì¤ë)¡£
184 .TP
185 .B EPERM
186 .\"O For
187 .\"O .BR sethostname (),
188 .\"O the caller did not have the
189 .\"O .B CAP_SYS_ADMIN
190 .\"O capability.
191 .BR sethostname ()
192 ¤Ë¤ª¤¤¤Æ¡¢¸Æ¤Ó½Ð¤·¤¿¿Í¤¬
193 .B CAP_SYS_ADMIN
194 ¥±¡¼¥Ñ¥Ó¥ê¥Æ¥£ (capability) ¤ò»ý¤Ã¤Æ¤¤¤Ê¤«¤Ã¤¿¡£
195 .\"O .SH "CONFORMING TO"
196 .SH ½àµò
197 .\"O SVr4, 4.4BSD  (these interfaces first appeared in 4.2BSD).
198 .\"O POSIX.1-2001 specifies
199 .\"O .BR gethostname ()
200 .\"O but not
201 .\"O .BR sethostname ().
202 SVr4, 4.4BSD  (¤³¤ì¤é¤Î¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤Ï 4.2BSD ¤Ç½é¤á¤ÆÅо줷¤¿)¡£
203 POSIX.1-2001 ¤Ç¤Ï
204 .BR gethostname ()
205 ¤Ë¤Ä¤¤¤Æ¤Ïµ¬Äꤷ¤Æ¤¤¤ë¤¬¡¢
206 .BR sethostname ()
207 ¤Ïµ¬Äꤷ¤Æ¤¤¤Ê¤¤¡£
208 .\"O .SH NOTES
209 .SH Ãí°Õ
210 .\"O SUSv2 guarantees that "Host names are limited to 255 bytes".
211 .\"O POSIX.1-2001 guarantees that "Host names (not including
212 .\"O the terminating null byte) are limited to
213 .\"O .B HOST_NAME_MAX
214 .\"O bytes".
215 SUSv2 ¤Ç¤Ï¡Ö¥Û¥¹¥È̾¤¬ 255 ¥Ð¥¤¥È¤ËÀ©¸Â¤µ¤ì¤ë¡×¤³¤È¤òÊݾڤ·¤Æ¤¤¤ë¡£
216 POSIX.1-2001 ¤Ç¤Ï¡Ö¥Û¥¹¥È̾ (½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤Ï´Þ¤Þ¤Ê¤¤) ¤¬
217 .B HOST_NAME_MAX
218 ¥Ð¥¤¥È¤ËÀ©¸Â¤µ¤ì¤ë¡×¤³¤È¤òÊݾڤ·¤Æ¤¤¤ë¡£
219 .\"O On Linux,
220 .\"O .B HOST_NAME_MAX
221 .\"O is defined with the value 64, which has been the limit since Linux 1.0
222 .\"O (earlier kernels imposed a limit of 8 bytes).
223 Linux ¤Ç¤Ï¡¢
224 .B HOST_NAME_MAX
225 ¤Ï 64 ¤ËÄêµÁ¤µ¤ì¤Æ¤ª¤ê¡¢
226 Linux 1.0 °Ê¹ß¤Ç¤Ï¤³¤ì¤¬¾å¸Â¤È¤Ê¤Ã¤Æ¤­¤¿
227 (¤â¤Ã¤È¸Å¤¤¥«¡¼¥Í¥ë¤Ç¤Ï 8 ¥Ð¥¤¥È¤Î¾å¸Â¤¬Å¬ÍѤµ¤ì¤Æ¤¤¤¿)¡£
228 .\"O .SS Glibc Notes
229 .SS "glibc ¤Ç¤ÎÃí°Õ"
230 .\"O The GNU C library does not employ the
231 .\"O .BR gethostname ()
232 .\"O system call; instead, it implements
233 .\"O .BR gethostname ()
234 .\"O as a library function that calls
235 .\"O .BR uname (2)
236 .\"O and copies up to
237 .\"O .I len
238 .\"O bytes from the returned
239 .\"O .I nodename
240 .\"O field into
241 .\"O .IR name .
242 GNU C ¥é¥¤¥Ö¥é¥ê¤Ï¡¢
243 .BR gethostname ()
244 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤òÍøÍѤ·¤Æ¤¤¤Ê¤¤¡£¤½¤ÎÂå¤ï¤ê¡¢
245 .BR gethostname ()
246 ¤ò¥é¥¤¥Ö¥é¥ê´Ø¿ô¤È¤·¤Æ¼ÂÁõ¤·¤Æ¤ª¤ê¡¢
247 ¤³¤Î´Ø¿ô¤Ï
248 .BR uname (2)
249 ¤ò¸Æ¤Ó½Ð¤·¡¢
250 .BR uname (2)
251 ¤¬ÊÖ¤·¤¿
252 .I nodename
253 ¥Õ¥£¡¼¥ë¥É (¤ÎºÇÂç
254 .I len
255 ¥Ð¥¤¥È) ¤ò
256 .I name
257 ¤Ë¥³¥Ô¡¼¤¹¤ë¡£
258 .\"O Having performed the copy, the function then checks if the length of the
259 .\"O .I nodename
260 .\"O was greater than or equal to
261 .\"O .IR len ,
262 .\"O and if it is, then the function returns \-1 with
263 .\"O .I errno
264 .\"O set to
265 .\"O .BR ENAMETOOLONG ;
266 .\"O in this case, a terminating null byte is not included in the returned
267 .\"O .IR name .
268 ¥³¥Ô¡¼¤ò¹Ô¤Ã¤¿ºÝ¤Ë¡¢¤³¤Î´Ø¿ô¤Ï
269 .I nodename
270 ¤ÎŤµ¤¬
271 .I len
272 °Ê¾å¤«¤Î³Îǧ¤ò¹Ô¤¤¡¢
273 .I len
274 °Ê¾å¤Î¾ì¹ç¤Ë¤Ï \-1 ¤òÊÖ¤·¡¢
275 .I errno
276 ¤Ë
277 .B ENAMETOOLONG
278 ¤òÀßÄꤹ¤ë¡£
279 ¤³¤Î¾ì¹ç¡¢ÊÖ¤µ¤ì¤¿
280 .I name
281 ¤Ë¤Ï½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤Ï´Þ¤Þ¤ì¤Ê¤¤¡£
282
283 .\"O Versions of glibc before 2.2
284 .\"O .\" At least glibc 2.0 and 2.1, older versions not checked
285 .\"O handle the case where the length of the
286 .\"O .I nodename
287 .\"O was greater than or equal to
288 .\"O .I len
289 .\"O differently: nothing is copied into
290 .\"O .I name
291 .\"O and the function returns \-1 with
292 .\"O .I errno
293 .\"O set to
294 .\"O .BR ENAMETOOLONG .
295 ¥Ð¡¼¥¸¥ç¥ó 2.2 ¤è¤êÁ°¤Î glibc
296 .\" ¾¯¤Ê¤¯¤È¤â glibc 2.0 ¤È 2.1¡£¤½¤ì¤è¤ê¸Å¤¤¥Ð¡¼¥¸¥ç¥ó¤Ï̤³Îǧ
297 ¤Ç¤Ï¡¢
298 .I nodename
299 ¤ÎŤµ¤¬
300 .I len
301 °Ê¾å¤Î¾ì¹ç¤Î°·¤¤¤¬°Û¤Ê¤ë;
302 .I len
303 °Ê¾å¤Î¾ì¹ç¤Ë¤Ï¡¢
304 .I name
305 ¤Ë¤Ï²¿¤â¥³¥Ô¡¼¤»¤º¡¢´Ø¿ô¤Ï \-1 ¤òÊÖ¤·¡¢
306 .I errno
307 ¤Ë
308 .B ENAMETOOLONG
309 ¤òÀßÄꤹ¤ë¡£
310 .\"O .SH "SEE ALSO"
311 .SH ´ØÏ¢¹àÌÜ
312 .BR getdomainname (2),
313 .BR setdomainname (2),
314 .BR uname (2)