1 .\" Copyright 2008, Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
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.
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.
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
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\"*******************************************************************
28 .\" This file was generated with po4a. Translate the source file.
30 .\"*******************************************************************
32 .\" Japanese Version Copyright (c) 2012 Akihiro MOTOKI
33 .\" all rights reserved.
34 .\" Translated 2012-05-06, Akihiro MOTOKI <amotoki@gmail.com>
36 .TH GETSERVENT_R 3 2010\-09\-10 GNU "Linux Programmer's Manual"
38 getservent_r, getservbyname_r, getservbyport_r \- サービスエントリを
42 \fB#include <netdb.h>\fP
44 \fBint getservent_r(struct servent *\fP\fIresult_buf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
45 \fB size_t \fP\fIbuflen\fP\fB, struct servent **\fP\fIresult\fP\fB);\fP
47 \fBint getservbyname_r(const char *\fP\fIname\fP\fB, const char *\fP\fIproto\fP\fB,\fP
48 \fB struct servent *\fP\fIresult_buf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
49 \fB size_t \fP\fIbuflen\fP\fB, struct servent **\fP\fIresult\fP\fB);\fP
51 \fBint getservbyport_r(int \fP\fIport\fP\fB, const char *\fP\fIproto\fP\fB,\fP
52 \fB struct servent *\fP\fIresult_buf\fP\fB, char *\fP\fIbuf\fP\fB,\fP
53 \fB size_t \fP\fIbuflen\fP\fB, struct servent **\fP\fIresult\fP\fB);\fP
57 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照):
61 \fBgetservent_r\fP(), \fBgetservbyname_r\fP(), \fBgetservbyport_r\fP():
63 _BSD_SOURCE || _SVID_SOURCE
67 関数 \fBgetservent_r\fP(), \fBgetservbyname_r\fP(), \fBgetservbyport_r\fP() は、
68 それぞれ \fBgetservent\fP(3), \fBgetservbyname\fP(3), \fBgetservbyport\fP(3) の
70 \fIservent\fP 構造体の返し方と、関数呼び出し時の引き数と返り値が異なる。
71 このマニュアルページでは、リエントラントでない関数との違いだけを
74 これらの関数は、関数の結果として静的に割り当てられた \fIservent\fP 構造体
75 へのポインタを返すのではなく、 \fIservent\fP 構造体を \fIresult_buf\fP が
78 .\" I can find no information on the required/recommended buffer size;
79 .\" the nonreentrant functions use a 1024 byte buffer -- mtk.
80 配列 \fIbuf\fP は、返される \fIservent\fP 構造体が指す文字列フィールドを
81 格納するのに使用される (リエントラントでない関数の場合は、
83 この配列の大きさは \fIbuflen\fP で指定される。
84 \fIbuf\fP が小さすぎる場合、関数呼び出しはエラー \fBERANGE\fP で失敗し、
85 呼び出し側ではもっと大きなバッファで再度呼び出す必要がある (ほとんどの
86 アプリケーションでは、長さ 1024 バイトのバッファで十分なはずである)。
88 関数呼び出しでサービスレコードの取得に成功すると、
89 \fI*result\fP は \fIresult_buf\fP を指すように設定される。
90 それ以外の場合は \fI*result\fP に NULL が設定される。
92 成功すると、これらの関数は 0 を返す。エラーの場合、「エラー」の節の
93 リストにある正のエラー番号のいずれかを返す。
95 エラーの場合、レコードが見つからなかった場合 (\fBgetservbyname_r\fP(),
96 \fBgetservbyaddr_r\fP()) やこれ以上レコードがない場合 (\fBgetservent_r\fP())、
97 \fIresult\fP には NULL が設定される。
101 (\fBgetservent_r\fP()) データベースにこれ以上レコードがない。
104 \fIbuf\fP が小さすぎる。もっと大きなバッファにして
105 (または \fIbuflen\fP を増やして) 再度呼び出すこと。
107 これらの関数は GNU による拡張である。
108 他のシステムにも同様の名前の関数が存在する場合があるが、
111 以下のプログラムは、 \fBgetservbyport_r\fP() を使って、コマンド
112 ライン引き数で指定されたポート番号とプロトコル名を持つ
114 三番目のコマンドライン引き数 (整数値) が指定された場合は、
115 その値が \fIbuflen\fP の初期値として使用される。
116 \fBgetservbyport_r\fP() がエラー \fBERANGE\fP で失敗すると、プログラムは
117 より大きなバッファサイズで再度 \fBgetservbyport_r\fP を呼び出す。
118 下記のシェルのセッションは実行例を示している。
122 $\fB ./a.out 7 tcp 1\fP
123 ERANGE! Retrying with larger buffer
124 getservbyport_r() returned: 0 (success) (buflen=87)
125 s_name=echo; s_proto=tcp; s_port=7; aliases=
126 $\fB ./a.out 77777 tcp\fP
127 getservbyport_r() returned: 0 (success) (buflen=1024)
128 Call failed/record not found
142 #define MAX_BUF 10000
145 main(int argc, char *argv[])
147 int buflen, erange_cnt, port, s;
148 struct servent result_buf;
149 struct servent *result;
155 printf("Usage: %s port\-num proto\-name [buflen]\en", argv[0]);
159 port = htons(atoi(argv[1]));
160 protop = (strcmp(argv[2], "null") == 0 ||
161 strcmp(argv[2], "NULL") == 0) ? NULL : argv[2];
165 buflen = atoi(argv[3]);
167 if (buflen > MAX_BUF) {
168 printf("Exceeded buffer limit (%d)\en", MAX_BUF);
174 s = getservbyport_r(port, protop, &result_buf,
175 buf, buflen, &result);
178 printf("ERANGE! Retrying with larger buffer\en");
181 /* Increment a byte at a time so we can see exactly
182 what size buffer was required */
186 if (buflen > MAX_BUF) {
187 printf("Exceeded buffer limit (%d)\en", MAX_BUF);
191 } while (s == ERANGE);
193 printf("getservbyport_r() returned: %s (buflen=%d)\en",
194 (s == 0) ? "0 (success)" : (s == ENOENT) ? "ENOENT" :
195 strerror(s), buflen);
197 if (s != 0 || result == NULL) {
198 printf("Call failed/record not found\en");
202 printf("s_name=%s; s_proto=%s; s_port=%d; aliases=",
203 result_buf.s_name, result_buf.s_proto,
204 ntohs(result_buf.s_port));
205 for (p = result_buf.s_aliases; *p != NULL; p++)
213 \fBgetservent\fP(3), \fBservices\fP(5)
215 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
216 である。プロジェクトの説明とバグ報告に関する情報は
217 http://www.kernel.org/doc/man\-pages/ に書かれている。