1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
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.
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.
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
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
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
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
42 .TH GETHOSTNAME 2 2008-11-27 "Linux" "Linux Programmer's Manual"
45 .\"O gethostname, sethostname \- get/set hostname
46 gethostname, sethostname \- ¥Û¥¹¥È̾¤Î¼èÆÀ¡¦ÀßÄê¤ò¤¹¤ë
49 .B #include <unistd.h>
51 .BI "int gethostname(char *" name ", size_t " len );
53 .BI "int sethostname(const char *" name ", size_t " len );
56 .\"O Feature Test Macro Requirements for glibc (see
57 .\"O .BR feature_test_macros (7)):
58 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
59 .RB ( feature_test_macros (7)
65 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
68 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
72 .\"O These system calls are used to access or to change the hostname of the
73 .\"O current processor.
74 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢¸½ºß¤Î¥×¥í¥»¥Ã¥µ¤Î¥Û¥¹¥È̾¤ò¼èÆÀ¡¦Êѹ¹¤¹¤ë¤¿¤á¤Ë
77 .\"O .BR sethostname ()
78 .\"O sets the hostname to the value given in the character array
82 .\"O argument specifies the number of bytes in
86 .\"O does not require a terminating null byte.)
88 ¤Ï¡¢¥Û¥¹¥È̾¤ò¡¢Ê¸»úÇÛÎó
90 ¤Ç»ØÄꤵ¤ì¤¿ÃͤËÀßÄꤹ¤ë¡£
98 ¤Ç¤Ïʸ»úÎó½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤ÏɬÍפʤ¤)¡£
100 .\"O .BR gethostname ()
101 .\"O returns the null-terminated hostname in the character array
103 .\"O which has a length of
106 .\"O If the null-terminated hostname is too large to fit,
107 .\"O then the name is truncated, and no error is returned (but see NOTES below).
108 .\"O POSIX.1-2001 says that if such truncation occurs,
109 .\"O then it is unspecified whether the returned buffer
110 .\"O includes a terminating null byte.
112 ¤Ï¡¢NULL ½ªÃ¼¤µ¤ì¤¿¥Û¥¹¥È̾¤ò¡¢
114 ¥Ð¥¤¥È¤ÎŤµ¤Îʸ»úÇÛÎó
117 NULL ½ªÃ¼¤µ¤ì¤¿¥Û¥¹¥È̾¤¬³ÊǼÀè¤Î¥Ð¥Ã¥Õ¥¡¤è¤ê¤âŤ¤¾ì¹ç¤Ï¡¢
118 ¥Û¥¹¥È̾¤ÏÀÚ¤êµÍ¤á¤é¤ì¡¢¥¨¥é¡¼¤ÏÊÖ¤µ¤ì¤Ê¤¤ (²¼µ¤Î¡ÖÃí°Õ¡×¤ÎÀá¤ò»²¾È)¡£
119 POSIX.1-2001 ¤Ç¤Ï¡¢·ë²Ì¤ÎÀÚ¤êµÍ¤á¤¬È¯À¸¤·¤¿¾ì¹ç¤Ë¡¢
120 ÊÖ¤µ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤Ë½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤Ï
122 .\"O .SH "RETURN VALUE"
124 .\"O On success, zero is returned.
125 .\"O On error, \-1 is returned, and
127 .\"O is set appropriately.
128 À®¸ù¤·¤¿¾ì¹ç 0 ¤¬Ê֤롣¼ºÇÔ¤·¤¿¾ì¹ç \-1 ¤¬Ê֤ꡢ
130 ¤¬¥¨¥é¡¼¤ÎÆâÍƤ˽¾¤Ã¤ÆÀßÄꤵ¤ì¤ë¡£
136 .\"O is an invalid address.
138 ¤¬ÉÔÀµ¤Ê¥¢¥É¥ì¥¹¤Ç¤¢¤ë¡£
143 .\"O .\" Can't occur for gethostbyname() wrapper, since 'len' has an
144 .\"O .\" unsigned type; can occur for the underlying system call.
146 .\"O .BR sethostname (),
148 .\"O is larger than the maximum allowed size.
151 .\" gethostbyname() ¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ç¤Ï¡¢'len' ¤Ï unsigned ·¿¤Ê¤Î¤Ç
152 .\" ¤³¤Î¥¨¥é¡¼¤¬È¯À¸¤¹¤ë¤³¤È¤Ï¤Ê¤¤¡£
153 .\" ¤½¤ÎÃæ¤Ç¸Æ¤Ð¤ì¤ë¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ç¤ÏȯÀ¸¤¹¤ë¤³¤È¤¬¤¢¤ë¡£
157 ¤¬µöÍƤµ¤ì¤¿ºÇÂ祵¥¤¥º¤ò±Û¤¨¤Æ¤¤¤ë¡£
160 .\"O .RB "(glibc " gethostname ())
162 .\"O is smaller than the actual size.
163 .\"O (Before version 2.1, glibc uses
166 .RB "(glibc " gethostname ()
169 ¤¬¼ÂºÝ¤Î¥Û¥¹¥È̾¤ÎŤµ¤è¤ê¤â¾®¤µ¤¤
170 (glibc ¥Ð¡¼¥¸¥ç¥ó 2.1 ¤è¤êÁ°¤Ç¤Ï¡¢¤³¤Î¾õ¶·¤Ç
176 .\"O .BR sethostname (),
177 .\"O the caller did not have the
178 .\"O .B CAP_SYS_ADMIN
181 ¤Ë¤ª¤¤¤Æ¡¢¸Æ¤Ó½Ð¤·¤¿¿Í¤¬
183 ¥±¡¼¥Ñ¥Ó¥ê¥Æ¥£ (capability) ¤ò»ý¤Ã¤Æ¤¤¤Ê¤«¤Ã¤¿¡£
184 .\"O .SH "CONFORMING TO"
186 .\"O SVr4, 4.4BSD (these interfaces first appeared in 4.2BSD).
187 .\"O POSIX.1-2001 specifies
188 .\"O .BR gethostname ()
190 .\"O .BR sethostname ().
191 SVr4, 4.4BSD (¤³¤ì¤é¤Î¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤Ï 4.2BSD ¤Ç½é¤á¤ÆÅо줷¤¿)¡£
194 ¤Ë¤Ä¤¤¤Æ¤Ïµ¬Äꤷ¤Æ¤¤¤ë¤¬¡¢
199 .\"O SUSv2 guarantees that "Host names are limited to 255 bytes".
200 .\"O POSIX.1-2001 guarantees that "Host names (not including
201 .\"O the terminating null byte) are limited to
202 .\"O .B HOST_NAME_MAX
204 SUSv2 ¤Ç¤Ï¡Ö¥Û¥¹¥È̾¤¬ 255 ¥Ð¥¤¥È¤ËÀ©¸Â¤µ¤ì¤ë¡×¤³¤È¤òÊݾڤ·¤Æ¤¤¤ë¡£
205 POSIX.1-2001 ¤Ç¤Ï¡Ö¥Û¥¹¥È̾ (½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤Ï´Þ¤Þ¤Ê¤¤) ¤¬
207 ¥Ð¥¤¥È¤ËÀ©¸Â¤µ¤ì¤ë¡×¤³¤È¤òÊݾڤ·¤Æ¤¤¤ë¡£
209 .\"O .B HOST_NAME_MAX
210 .\"O is defined with the value 64, which has been the limit since Linux 1.0
211 .\"O (earlier kernels imposed a limit of 8 bytes).
214 ¤Ï 64 ¤ËÄêµÁ¤µ¤ì¤Æ¤ª¤ê¡¢
215 Linux 1.0 °Ê¹ß¤Ç¤Ï¤³¤ì¤¬¾å¸Â¤È¤Ê¤Ã¤Æ¤¤¿
216 (¤â¤Ã¤È¸Å¤¤¥«¡¼¥Í¥ë¤Ç¤Ï 8 ¥Ð¥¤¥È¤Î¾å¸Â¤¬Å¬ÍѤµ¤ì¤Æ¤¤¤¿)¡£
219 .\"O The GNU C library does not employ the
220 .\"O .BR gethostname ()
221 .\"O system call; instead, it implements
222 .\"O .BR gethostname ()
223 .\"O as a library function that calls
225 .\"O and copies up to
227 .\"O bytes from the returned
233 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤òÍøÍѤ·¤Æ¤¤¤Ê¤¤¡£¤½¤ÎÂå¤ï¤ê¡¢
235 ¤ò¥é¥¤¥Ö¥é¥ê´Ø¿ô¤È¤·¤Æ¼ÂÁõ¤·¤Æ¤ª¤ê¡¢
247 .\"O Having performed the copy, the function then checks if the length of the
249 .\"O was greater than or equal to
251 .\"O and if it is, then the function returns \-1 with
254 .\"O .BR ENAMETOOLONG ;
255 .\"O in this case, no null-terminator is included in the returned
257 ¥³¥Ô¡¼¤ò¹Ô¤Ã¤¿ºÝ¤Ë¡¢¤³¤Î´Ø¿ô¤Ï
263 °Ê¾å¤Î¾ì¹ç¤Ë¤Ï \-1 ¤òÊÖ¤·¡¢
270 ¤Ë¤Ï½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤Ï´Þ¤Þ¤ì¤Ê¤¤¡£
272 .\"O Versions of glibc before 2.2
273 .\"O .\" At least glibc 2.0 and 2.1, older versions not checked
274 .\"O handle the case where the length of the
276 .\"O was greater than or equal to
278 .\"O differently: nothing is copied into
280 .\"O and the function returns \-1 with
283 .\"O .BR ENAMETOOLONG .
284 ¥Ð¡¼¥¸¥ç¥ó 2.2 ¤è¤êÁ°¤Î glibc
285 .\" ¾¯¤Ê¤¯¤È¤â glibc 2.0 ¤È 2.1¡£¤½¤ì¤è¤ê¸Å¤¤¥Ð¡¼¥¸¥ç¥ó¤Ï̤³Îǧ
290 °Ê¾å¤Î¾ì¹ç¤Î°·¤¤¤¬°Û¤Ê¤ë;
294 ¤Ë¤Ï²¿¤â¥³¥Ô¡¼¤»¤º¡¢´Ø¿ô¤Ï \-1 ¤òÊÖ¤·¡¢
301 .BR getdomainname (2),
302 .BR setdomainname (2),