OSDN Git Service

(split) LDP: Update the version to 3.53 in PO files
[linuxjm/LDP_man-pages.git] / release / man3 / getprotoent_r.3
1 .\" Copyright 2008, Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
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 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .TH GETPROTOENT_R 3 2010\-09\-10 GNU "Linux Programmer's Manual"
32 .SH 名前
33 getprotoent_r, getprotobyname_r, getprotobynumber_r \- プロトコル
34 エントリを取得する (リエントラント版)
35 .SH 書式
36 .nf
37 \fB#include <netdb.h>\fP
38 .sp
39 \fBint getprotoent_r(struct protoent *\fP\fIresult_buf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
40 \fB                size_t \fP\fIbuflen\fP\fB, struct protoent **\fP\fIresult\fP\fB);\fP
41 .sp
42 \fBint getprotobyname_r(const char *\fP\fIname\fP\fB,\fP
43 \fB                struct protoent *\fP\fIresult_buf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
44 \fB                size_t \fP\fIbuflen\fP\fB, struct protoent **\fP\fIresult\fP\fB);\fP
45 .sp
46 \fBint getprotobynumber_r(int \fP\fIproto\fP\fB,\fP
47 \fB                struct protoent *\fP\fIresult_buf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
48 \fB                size_t \fP\fIbuflen\fP\fB, struct protoent **\fP\fIresult\fP\fB);\fP
49 .sp
50 .fi
51 .in -4n
52 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
53 .ad l
54 .in
55 .sp
56 \fBgetprotoent_r\fP(), \fBgetprotobyname_r\fP(), \fBgetprotobynumber_r\fP():
57 .RS 4
58 _BSD_SOURCE || _SVID_SOURCE
59 .RE
60 .ad b
61 .SH 説明
62 関数 \fBgetprotoent_r\fP(), \fBgetprotobyname_r\fP(),
63 \fBgetprotobynumber_r\fP() は、それぞれ \fBgetprotoent\fP(3),
64 \fBgetprotobyname\fP(3), \fBgetprotobynumber\fP(3) のリエントラント版である。
65 \fIprotoent\fP 構造体の返し方と、関数呼び出し時の引き数と返り値が異なる。
66 このマニュアルページでは、リエントラントでない関数との違いだけを
67 説明する。
68
69 これらの関数は、関数の結果として静的に割り当てられた \fIprotoent\fP 構造体
70 へのポインタを返すのではなく、 \fIprotoent\fP 構造体を \fIresult_buf\fP が
71 指す場所にコピーする。
72
73 .\" I can find no information on the required/recommended buffer size;
74 .\" the nonreentrant functions use a 1024 byte buffer.
75 .\" The 1024 byte value is also what the Solaris man page suggests. -- mtk
76 配列 \fIbuf\fP は、返される \fIprotoent\fP 構造体が指す文字列フィールドを
77 格納するのに使用される (リエントラントでない関数の場合は、
78 これらの文字列は静的な領域に格納される)。
79 この配列の大きさは \fIbuflen\fP で指定される。
80 \fIbuf\fP が小さすぎる場合、関数呼び出しはエラー \fBERANGE\fP で失敗し、
81 呼び出し側ではもっと大きなバッファで再度呼び出す必要がある (ほとんどの
82 アプリケーションでは、長さ 1024 バイトのバッファで十分なはずである)。
83
84 関数呼び出しでプロトコルレコードの取得に成功すると、
85 \fI*result\fP は \fIresult_buf\fP を指すように設定される。
86 それ以外の場合は \fI*result\fP に NULL が設定される。
87 .SH 返り値
88 成功すると、これらの関数は 0 を返す。エラーの場合、「エラー」の節の
89 リストにある正のエラー番号のいずれかを返す。
90
91 エラーの場合、レコードが見つからなかった場合 (\fBgetprotobyname_r\fP(),
92 \fBgetprotobyaddr_r\fP()) やこれ以上レコードがない場合
93 (\fBgetprotoent_r\fP())、\fIresult\fP には NULL が設定される。
94 .SH エラー
95 .TP 
96 \fBENOENT\fP
97 (\fBgetprotoent_r\fP())  データベースにこれ以上レコードがない。
98 .TP 
99 \fBERANGE\fP
100 \fIbuf\fP が小さすぎる。もっと大きなバッファにして
101 (または \fIbuflen\fP を増やして) 再度呼び出すこと。
102 .SH 準拠
103 これらの関数は GNU による拡張である。
104 他のシステムにも同様の名前の関数が存在する場合があるが、
105 通常は関数の引き数が異なる。
106 .SH 例
107 以下のプログラムは、 \fBgetprotobyname_r\fP() を使って、最初のコマンド
108 ライン引き数で指定された名前のプロトコルのレコードを取得する。
109 二番目のコマンドライン引き数 (整数値) が指定された場合は、
110 その値が \fIbuflen\fP の初期値として使用される。
111 \fBgetprotobyname_r\fP() がエラー \fBERANGE\fP で失敗すると、プログラムは
112 より大きなバッファサイズで再度 \fBgetprotobyname_r\fP を呼び出す。
113 下記のシェルのセッションは、実行例を示している。
114 .in +4n
115 .nf
116
117 $\fB ./a.out tcp 1\fP
118 ERANGE! Retrying with larger buffer
119 getprotobyname_r() returned: 0 (success)  (buflen=78)
120 p_name=tcp; p_proto=6; aliases=TCP
121 $\fB ./a.out xxx 1\fP
122 ERANGE! Retrying with larger buffer
123 getprotobyname_r() returned: 0 (success)  (buflen=100)
124 Call failed/record not found
125 .fi
126 .in
127 .SS プログラムのソース
128 \&
129 .nf
130 #define _GNU_SOURCE
131 #include <ctype.h>
132 #include <netdb.h>
133 #include <stdlib.h>
134 #include <stdio.h>
135 #include <errno.h>
136 #include <string.h>
137
138 #define MAX_BUF 10000
139
140 int
141 main(int argc, char *argv[])
142 {
143     int buflen, erange_cnt, s;
144     struct protoent result_buf;
145     struct protoent *result;
146     char buf[MAX_BUF];
147     char **p;
148
149     if (argc < 2) {
150         printf("Usage: %s proto\-name [buflen]\en", argv[0]);
151         exit(EXIT_FAILURE);
152     }
153
154     buflen = 1024;
155     if (argc > 2)
156         buflen = atoi(argv[2]);
157
158     if (buflen > MAX_BUF) {
159         printf("Exceeded buffer limit (%d)\en", MAX_BUF);
160         exit(EXIT_FAILURE);
161     }
162
163     erange_cnt = 0;
164     do {
165         s = getprotobyname_r(argv[1], &result_buf,
166                      buf, buflen, &result);
167         if (s == ERANGE) {
168             if (erange_cnt == 0)
169                 printf("ERANGE! Retrying with larger buffer\en");
170             erange_cnt++;
171
172             /* Increment a byte at a time so we can see exactly
173                what size buffer was required */
174
175             buflen++;
176
177             if (buflen > MAX_BUF) {
178                 printf("Exceeded buffer limit (%d)\en", MAX_BUF);
179                 exit(EXIT_FAILURE);
180             }
181         }
182     } while (s == ERANGE);
183
184     printf("getprotobyname_r() returned: %s  (buflen=%d)\en",
185             (s == 0) ? "0 (success)" : (s == ENOENT) ? "ENOENT" :
186             strerror(s), buflen);
187
188     if (s != 0 || result == NULL) {
189         printf("Call failed/record not found\en");
190         exit(EXIT_FAILURE);
191     }
192
193     printf("p_name=%s; p_proto=%d; aliases=",
194                 result_buf.p_name, result_buf.p_proto);
195     for (p = result_buf.p_aliases; *p != NULL; p++)
196         printf("%s ", *p);
197     printf("\en");
198
199     exit(EXIT_SUCCESS);
200 }
201 .fi
202 .SH 関連項目
203 \fBgetprotoent\fP(3), \fBprotocols\fP(5)
204 .SH この文書について
205 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
206 である。プロジェクトの説明とバグ報告に関する情報は
207 http://www.kernel.org/doc/man\-pages/ に書かれている。