OSDN Git Service

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