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 2010-09-26 "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)
67 .\"O Since glibc 2.12:
69 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
71 .\"O || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200112L
72 || /* glibc 2.12 °Ê¹ß: */ _POSIX_C_SOURCE\ >=\ 200112L
77 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
83 .\"O These system calls are used to access or to change the hostname of the
84 .\"O current processor.
85 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢¸½ºß¤Î¥×¥í¥»¥Ã¥µ¤Î¥Û¥¹¥È̾¤ò¼èÆÀ¡¦Êѹ¹¤¹¤ë¤¿¤á¤Ë
88 .\"O .BR sethostname ()
89 .\"O sets the hostname to the value given in the character array
93 .\"O argument specifies the number of bytes in
97 .\"O does not require a terminating null byte.)
99 ¤Ï¡¢¥Û¥¹¥È̾¤ò¡¢Ê¸»úÇÛÎó
101 ¤Ç»ØÄꤵ¤ì¤¿ÃͤËÀßÄꤹ¤ë¡£
109 ¤Ç¤Ïʸ»úÎó½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤ÏɬÍפʤ¤)¡£
111 .\"O .BR gethostname ()
112 .\"O returns the null-terminated hostname in the character array
114 .\"O which has a length of
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.
123 ¤Ï¡¢NULL ½ªÃ¼¤µ¤ì¤¿¥Û¥¹¥È̾¤ò¡¢
125 ¥Ð¥¤¥È¤ÎŤµ¤Îʸ»úÇÛÎó
128 NULL ½ªÃ¼¤µ¤ì¤¿¥Û¥¹¥È̾¤¬³ÊǼÀè¤Î¥Ð¥Ã¥Õ¥¡¤è¤ê¤âŤ¤¾ì¹ç¤Ï¡¢
129 ¥Û¥¹¥È̾¤ÏÀÚ¤êµÍ¤á¤é¤ì¡¢¥¨¥é¡¼¤ÏÊÖ¤µ¤ì¤Ê¤¤ (²¼µ¤Î¡ÖÃí°Õ¡×¤ÎÀá¤ò»²¾È)¡£
130 POSIX.1-2001 ¤Ç¤Ï¡¢·ë²Ì¤ÎÀÚ¤êµÍ¤á¤¬È¯À¸¤·¤¿¾ì¹ç¤Ë¡¢
131 ÊÖ¤µ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤Ë½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤Ï
133 .\"O .SH "RETURN VALUE"
135 .\"O On success, zero is returned.
136 .\"O On error, \-1 is returned, and
138 .\"O is set appropriately.
139 À®¸ù¤·¤¿¾ì¹ç 0 ¤¬Ê֤롣¼ºÇÔ¤·¤¿¾ì¹ç \-1 ¤¬Ê֤ꡢ
141 ¤¬¥¨¥é¡¼¤ÎÆâÍƤ˽¾¤Ã¤ÆÀßÄꤵ¤ì¤ë¡£
147 .\"O is an invalid address.
149 ¤¬ÉÔÀµ¤Ê¥¢¥É¥ì¥¹¤Ç¤¢¤ë¡£
154 .\"O .\" Can't occur for gethostbyname() wrapper, since 'len' has an
155 .\"O .\" unsigned type; can occur for the underlying system call.
157 .\"O .BR sethostname (),
159 .\"O is larger than the maximum allowed size.
162 .\" gethostbyname() ¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ç¤Ï¡¢'len' ¤Ï unsigned ·¿¤Ê¤Î¤Ç
163 .\" ¤³¤Î¥¨¥é¡¼¤¬È¯À¸¤¹¤ë¤³¤È¤Ï¤Ê¤¤¡£
164 .\" ¤½¤ÎÃæ¤Ç¸Æ¤Ð¤ì¤ë¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ç¤ÏȯÀ¸¤¹¤ë¤³¤È¤¬¤¢¤ë¡£
168 ¤¬µöÍƤµ¤ì¤¿ºÇÂ祵¥¤¥º¤ò±Û¤¨¤Æ¤¤¤ë¡£
171 .\"O .RB "(glibc " gethostname ())
173 .\"O is smaller than the actual size.
174 .\"O (Before version 2.1, glibc uses
177 .RB "(glibc " gethostname ()
180 ¤¬¼ÂºÝ¤Î¥Û¥¹¥È̾¤ÎŤµ¤è¤ê¤â¾®¤µ¤¤
181 (glibc ¥Ð¡¼¥¸¥ç¥ó 2.1 ¤è¤êÁ°¤Ç¤Ï¡¢¤³¤Î¾õ¶·¤Ç
187 .\"O .BR sethostname (),
188 .\"O the caller did not have the
189 .\"O .B CAP_SYS_ADMIN
192 ¤Ë¤ª¤¤¤Æ¡¢¸Æ¤Ó½Ð¤·¤¿¿Í¤¬
194 ¥±¡¼¥Ñ¥Ó¥ê¥Æ¥£ (capability) ¤ò»ý¤Ã¤Æ¤¤¤Ê¤«¤Ã¤¿¡£
195 .\"O .SH "CONFORMING TO"
197 .\"O SVr4, 4.4BSD (these interfaces first appeared in 4.2BSD).
198 .\"O POSIX.1-2001 specifies
199 .\"O .BR gethostname ()
201 .\"O .BR sethostname ().
202 SVr4, 4.4BSD (¤³¤ì¤é¤Î¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤Ï 4.2BSD ¤Ç½é¤á¤ÆÅо줷¤¿)¡£
205 ¤Ë¤Ä¤¤¤Æ¤Ïµ¬Äꤷ¤Æ¤¤¤ë¤¬¡¢
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
215 SUSv2 ¤Ç¤Ï¡Ö¥Û¥¹¥È̾¤¬ 255 ¥Ð¥¤¥È¤ËÀ©¸Â¤µ¤ì¤ë¡×¤³¤È¤òÊݾڤ·¤Æ¤¤¤ë¡£
216 POSIX.1-2001 ¤Ç¤Ï¡Ö¥Û¥¹¥È̾ (½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤Ï´Þ¤Þ¤Ê¤¤) ¤¬
218 ¥Ð¥¤¥È¤ËÀ©¸Â¤µ¤ì¤ë¡×¤³¤È¤òÊݾڤ·¤Æ¤¤¤ë¡£
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).
225 ¤Ï 64 ¤ËÄêµÁ¤µ¤ì¤Æ¤ª¤ê¡¢
226 Linux 1.0 °Ê¹ß¤Ç¤Ï¤³¤ì¤¬¾å¸Â¤È¤Ê¤Ã¤Æ¤¤¿
227 (¤â¤Ã¤È¸Å¤¤¥«¡¼¥Í¥ë¤Ç¤Ï 8 ¥Ð¥¤¥È¤Î¾å¸Â¤¬Å¬ÍѤµ¤ì¤Æ¤¤¤¿)¡£
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
236 .\"O and copies up to
238 .\"O bytes from the returned
244 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤òÍøÍѤ·¤Æ¤¤¤Ê¤¤¡£¤½¤ÎÂå¤ï¤ê¡¢
246 ¤ò¥é¥¤¥Ö¥é¥ê´Ø¿ô¤È¤·¤Æ¼ÂÁõ¤·¤Æ¤ª¤ê¡¢
258 .\"O Having performed the copy, the function then checks if the length of the
260 .\"O was greater than or equal to
262 .\"O and if it is, then the function returns \-1 with
265 .\"O .BR ENAMETOOLONG ;
266 .\"O in this case, a terminating null byte is not included in the returned
268 ¥³¥Ô¡¼¤ò¹Ô¤Ã¤¿ºÝ¤Ë¡¢¤³¤Î´Ø¿ô¤Ï
274 °Ê¾å¤Î¾ì¹ç¤Ë¤Ï \-1 ¤òÊÖ¤·¡¢
281 ¤Ë¤Ï½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤Ï´Þ¤Þ¤ì¤Ê¤¤¡£
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
287 .\"O was greater than or equal to
289 .\"O differently: nothing is copied into
291 .\"O and the function returns \-1 with
294 .\"O .BR ENAMETOOLONG .
295 ¥Ð¡¼¥¸¥ç¥ó 2.2 ¤è¤êÁ°¤Î glibc
296 .\" ¾¯¤Ê¤¯¤È¤â glibc 2.0 ¤È 2.1¡£¤½¤ì¤è¤ê¸Å¤¤¥Ð¡¼¥¸¥ç¥ó¤Ï̤³Îǧ
301 °Ê¾å¤Î¾ì¹ç¤Î°·¤¤¤¬°Û¤Ê¤ë;
305 ¤Ë¤Ï²¿¤â¥³¥Ô¡¼¤»¤º¡¢´Ø¿ô¤Ï \-1 ¤òÊÖ¤·¡¢
312 .BR getdomainname (2),
313 .BR setdomainname (2),