OSDN Git Service

a0a474724f4471b8edec6ce15e47fc3d7552cc68
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man2 / gethostname.2
1 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified 1995-07-22 by Michael Chastain <mec@duracef.shout.net>:
26 .\"   'gethostname' is real system call on Linux/Alpha.
27 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified 2000-06-04, 2001-12-15 by aeb
29 .\" Modified 2004-06-17 by mtk
30 .\" Modified 2008-11-27 by mtk
31 .\"
32 .\"*******************************************************************
33 .\"
34 .\" This file was generated with po4a. Translate the source file.
35 .\"
36 .\"*******************************************************************
37 .\"
38 .\" Japanese Version Copyright (c) 1997 SUTO, Mitsuaki
39 .\"         all rights reserved.
40 .\" Translated 1997-06-27, SUTO, Mitsuaki <suto@av.crl.sony.co.jp>
41 .\" Updated 2000-09-30, Yuichi SATO <sato@complex.eng.hokudai.ac.jp>
42 .\" Updated & Modified 2002-01-14, Yuichi SATO <ysato@h4.dion.ne.jp>
43 .\" Updated & Modified 2004-12-30, Yuichi SATO <ysato444@yahoo.co.jp>
44 .\" Updated & Modified 2006-01-31, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
45 .\" Updated 2008-12-26, Akihiro MOTOKI, LDP v3.15
46 .\"
47 .TH GETHOSTNAME 2 2019\-10\-10 Linux "Linux Programmer's Manual"
48 .SH 名前
49 gethostname, sethostname \- ホスト名の取得・設定をする
50 .SH 書式
51 \fB#include <unistd.h>\fP
52 .PP
53 \fBint gethostname(char *\fP\fIname\fP\fB, size_t \fP\fIlen\fP\fB);\fP
54 .br
55 \fBint sethostname(const char *\fP\fIname\fP\fB, size_t \fP\fIlen\fP\fB);\fP
56 .PP
57 .RS -4
58 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
59 .RE
60 .PP
61 .ad l
62 .PD 0
63 \fBgethostname\fP():
64 .RS 4
65 glibc 2.12 以降: _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
66 .br
67 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200112L
68 .RE
69 .br
70 \fBsethostname\fP():
71 .nf
72 .\"             commit 266865c0e7b79d4196e2cc393693463f03c90bd8
73     Since glibc 2.21:
74         _DEFAULT_SOURCE
75     In glibc 2.19 and 2.20:
76         _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
77     Up to and including glibc 2.19:
78         _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
79 .fi
80 .PD
81 .ad
82 .SH 説明
83 These system calls are used to access or to change the system hostname.
84 More precisely, they operate on the hostname associated with the calling
85 process's UTS namespace.
86 .PP
87 \fBsethostname\fP()  は、ホスト名を、文字配列 \fIname\fP で指定された値に設定する。 引き数 \fIlen\fP には、 \fIname\fP
88 のバイト数を指定する (そのため、 \fIname\fP では文字列終端のヌルバイトは必要ない)。
89 .PP
90 \fBgethostname\fP()  returns the null\-terminated hostname in the character
91 array \fIname\fP, which has a length of \fIlen\fP bytes.  If the null\-terminated
92 hostname is too large to fit, then the name is truncated, and no error is
93 returned (but see NOTES below).  POSIX.1 says that if such truncation
94 occurs, then it is unspecified whether the returned buffer includes a
95 terminating null byte.
96 .SH 返り値
97 成功した場合は 0 が返される。エラーの場合は \-1 が返され、 \fIerrno\fP が適切に設定される。
98 .SH エラー
99 .TP 
100 \fBEFAULT\fP
101 \fIname\fP が不正なアドレスである。
102 .TP 
103 \fBEINVAL\fP
104 .\" Can't occur for gethostbyname() wrapper, since 'len' has an
105 .\" unsigned type; can occur for the underlying system call.
106 \fIlen\fP が負である。 \fBsethostname\fP()  において \fIlen\fP が許容された最大サイズを越えている。
107 .TP 
108 \fBENAMETOOLONG\fP
109 (glibc \fBgethostname\fP()  で)  \fIlen\fP が実際のホスト名の長さよりも小さい (glibc バージョン 2.1
110 より前では、この状況で \fBEINVAL\fP が使用される)。
111 .TP 
112 \fBEPERM\fP
113 For \fBsethostname\fP(), the caller did not have the \fBCAP_SYS_ADMIN\fP
114 capability in the user namespace associated with its UTS namespace (see
115 \fBnamespaces\fP(7)).
116 .SH 準拠
117 SVr4, 4.4BSD (these interfaces first appeared in 4.2BSD).  POSIX.1\-2001 and
118 POSIX.1\-2008 specify \fBgethostname\fP()  but not \fBsethostname\fP().
119 .SH 注意
120 SUSv2 guarantees that "Host names are limited to 255 bytes".  POSIX.1
121 guarantees that "Host names (not including the terminating null byte) are
122 limited to \fBHOST_NAME_MAX\fP bytes".  On Linux, \fBHOST_NAME_MAX\fP is defined
123 with the value 64, which has been the limit since Linux 1.0 (earlier kernels
124 imposed a limit of 8 bytes).
125 .SS "C ライブラリとカーネルの違い"
126 GNU C ライブラリは、 \fBgethostname\fP()  システムコールを利用していない。その代わり、 \fBgethostname\fP()
127 をライブラリ関数として実装しており、 この関数は \fBuname\fP(2)  を呼び出し、 \fBuname\fP(2)  が返した \fInodename\fP
128 フィールド (の最大 \fIlen\fP バイト) を \fIname\fP にコピーする。 コピーを行った際に、この関数は \fInodename\fP の長さが
129 \fIlen\fP 以上かの確認を行い、 \fIlen\fP 以上の場合には \-1 を返し、 \fIerrno\fP に \fBENAMETOOLONG\fP を設定する。
130 この場合、返された \fIname\fP には終端のヌルバイトは含まれない。
131 .PP
132 .\" At least glibc 2.0 and 2.1, older versions not checked
133 バージョン 2.2 より前の glibc では、 \fInodename\fP の長さが \fIlen\fP 以上の場合の扱いが異なる; \fIlen\fP
134 以上の場合には、 \fIname\fP には何もコピーせず、関数は \-1 を返し、 \fIerrno\fP に \fBENAMETOOLONG\fP を設定する。
135 .SH 関連項目
136 \fBhostname\fP(1), \fBgetdomainname\fP(2), \fBsetdomainname\fP(2), \fBuname\fP(2),
137 \fButs_namespaces\fP(7)
138 .SH この文書について
139 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
140 \%https://www.kernel.org/doc/man\-pages/ に書かれている。