1 .\" Copyright 2008, Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"*******************************************************************
26 .\" This file was generated with po4a. Translate the source file.
28 .\"*******************************************************************
29 .TH GETPROTOENT_R 3 2010\-09\-10 GNU "Linux Programmer's Manual"
31 getprotoent_r, getprotobyname_r, getprotobynumber_r \- プロトコル
35 \fB#include <netdb.h>\fP
37 \fBint getprotoent_r(struct protoent *\fP\fIresult_buf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
38 \fB size_t \fP\fIbuflen\fP\fB, struct protoent **\fP\fIresult\fP\fB);\fP
40 \fBint getprotobyname_r(const char *\fP\fIname\fP\fB,\fP
41 \fB struct protoent *\fP\fIresult_buf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
42 \fB size_t \fP\fIbuflen\fP\fB, struct protoent **\fP\fIresult\fP\fB);\fP
44 \fBint getprotobynumber_r(int \fP\fIproto\fP\fB,\fP
45 \fB struct protoent *\fP\fIresult_buf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
46 \fB size_t \fP\fIbuflen\fP\fB, struct protoent **\fP\fIresult\fP\fB);\fP
50 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照):
54 \fBgetprotoent_r\fP(), \fBgetprotobyname_r\fP(), \fBgetprotobynumber_r\fP():
56 _BSD_SOURCE || _SVID_SOURCE
60 関数 \fBgetprotoent_r\fP(), \fBgetprotobyname_r\fP(),
61 \fBgetprotobynumber_r\fP() は、それぞれ \fBgetprotoent\fP(3),
62 \fBgetprotobyname\fP(3), \fBgetprotobynumber\fP(3) のリエントラント版である。
63 \fIprotoent\fP 構造体の返し方と、関数呼び出し時の引き数と返り値が異なる。
64 このマニュアルページでは、リエントラントでない関数との違いだけを
67 これらの関数は、関数の結果として静的に割り当てられた \fIprotoent\fP 構造体
68 へのポインタを返すのではなく、 \fIprotoent\fP 構造体を \fIresult_buf\fP が
71 .\" I can find no information on the required/recommended buffer size;
72 .\" the nonreentrant functions use a 1024 byte buffer.
73 .\" The 1024 byte value is also what the Solaris man page suggests. -- mtk
74 配列 \fIbuf\fP は、返される \fIprotoent\fP 構造体が指す文字列フィールドを
75 格納するのに使用される (リエントラントでない関数の場合は、
77 この配列の大きさは \fIbuflen\fP で指定される。
78 \fIbuf\fP が小さすぎる場合、関数呼び出しはエラー \fBERANGE\fP で失敗し、
79 呼び出し側ではもっと大きなバッファで再度呼び出す必要がある (ほとんどの
80 アプリケーションでは、長さ 1024 バイトのバッファで十分なはずである)。
82 関数呼び出しでプロトコルレコードの取得に成功すると、
83 \fI*result\fP は \fIresult_buf\fP を指すように設定される。
84 それ以外の場合は \fI*result\fP に NULL が設定される。
86 成功すると、これらの関数は 0 を返す。エラーの場合、「エラー」の節の
87 リストにある正のエラー番号のいずれかを返す。
89 エラーの場合、レコードが見つからなかった場合 (\fBgetprotobyname_r\fP(),
90 \fBgetprotobyaddr_r\fP()) やこれ以上レコードがない場合
91 (\fBgetprotoent_r\fP())、\fIresult\fP には NULL が設定される。
95 (\fBgetprotoent_r\fP()) データベースにこれ以上レコードがない。
98 \fIbuf\fP が小さすぎる。もっと大きなバッファにして
99 (または \fIbuflen\fP を増やして) 再度呼び出すこと。
101 これらの関数は GNU による拡張である。
102 他のシステムにも同様の名前の関数が存在する場合があるが、
105 以下のプログラムは、 \fBgetprotobyname_r\fP() を使って、最初のコマンド
106 ライン引き数で指定された名前のプロトコルのレコードを取得する。
107 二番目のコマンドライン引き数 (整数値) が指定された場合は、
108 その値が \fIbuflen\fP の初期値として使用される。
109 \fBgetprotobyname_r\fP() がエラー \fBERANGE\fP で失敗すると、プログラムは
110 より大きなバッファサイズで再度 \fBgetprotobyname_r\fP を呼び出す。
111 下記のシェルのセッションは、実行例を示している。
115 $\fB ./a.out tcp 1\fP
116 ERANGE! Retrying with larger buffer
117 getprotobyname_r() returned: 0 (success) (buflen=78)
118 p_name=tcp; p_proto=6; aliases=TCP
119 $\fB ./a.out xxx 1\fP
120 ERANGE! Retrying with larger buffer
121 getprotobyname_r() returned: 0 (success) (buflen=100)
122 Call failed/record not found
136 #define MAX_BUF 10000
139 main(int argc, char *argv[])
141 int buflen, erange_cnt, s;
142 struct protoent result_buf;
143 struct protoent *result;
148 printf("Usage: %s proto\-name [buflen]\en", argv[0]);
154 buflen = atoi(argv[2]);
156 if (buflen > MAX_BUF) {
157 printf("Exceeded buffer limit (%d)\en", MAX_BUF);
163 s = getprotobyname_r(argv[1], &result_buf,
164 buf, buflen, &result);
167 printf("ERANGE! Retrying with larger buffer\en");
170 /* Increment a byte at a time so we can see exactly
171 what size buffer was required */
175 if (buflen > MAX_BUF) {
176 printf("Exceeded buffer limit (%d)\en", MAX_BUF);
180 } while (s == ERANGE);
182 printf("getprotobyname_r() returned: %s (buflen=%d)\en",
183 (s == 0) ? "0 (success)" : (s == ENOENT) ? "ENOENT" :
184 strerror(s), buflen);
186 if (s != 0 || result == NULL) {
187 printf("Call failed/record not found\en");
191 printf("p_name=%s; p_proto=%d; aliases=",
192 result_buf.p_name, result_buf.p_proto);
193 for (p = result_buf.p_aliases; *p != NULL; p++)
201 \fBgetprotoent\fP(3), \fBprotocols\fP(5)
203 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.40 の一部
204 である。プロジェクトの説明とバグ報告に関する情報は
205 http://www.kernel.org/doc/man\-pages/ に書かれている。