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