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 \- get protocol entry
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 The \fBgetprotoent_r\fP(), \fBgetprotobyname_r\fP(), and \fBgetprotobynumber_r\fP()
61 functions are the reentrant equivalents of, respectively, \fBgetprotoent\fP(3),
62 \fBgetprotobyname\fP(3), and \fBgetprotobynumber\fP(3). They differ in the way
63 that the \fIprotoent\fP structure is returned, and in the function calling
64 signature and return value. This manual page describes just the differences
65 from the nonreentrant functions.
67 Instead of returning a pointer to a statically allocated \fIprotoent\fP
68 structure as the function result, these functions copy the structure into
69 the location pointed to by \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 The \fIbuf\fP array is used to store the string fields pointed to by the
75 returned \fIprotoent\fP structure. (The nonreentrant functions allocate these
76 strings in static storage.) The size of this array is specified in
77 \fIbuflen\fP. If \fIbuf\fP is too small, the call fails with the error \fBERANGE\fP,
78 and the caller must try again with a larger buffer. (A buffer of length
79 1024 bytes should be sufficient for most applications.)
81 If the function call successfully obtains a protocol record, then \fI*result\fP
82 is set pointing to \fIresult_buf\fP; otherwise, \fI*result\fP is set to NULL.
84 On success, these functions return 0. On error, they return one of the
85 positive error numbers listed in ERRORS.
87 On error, record not found (\fBgetprotobyname_r\fP(), \fBgetprotobynumber_r\fP()),
88 or end of input (\fBgetprotoent_r\fP()) \fIresult\fP is set to NULL.
92 (\fBgetprotoent_r\fP()) No more records in database.
95 \fIbuf\fP is too small. Try again with a larger buffer (and increased
98 These functions are GNU extensions. Functions with similar names exist on
99 some other systems, though typically with different calling signatures.
101 The program below uses \fBgetprotobyname_r\fP() to retrieve the protocol
102 record for the protocol named in its first command\-line argument. If a
103 second (integer) command\-line argument is supplied, it is used as the
104 initial value for \fIbuflen\fP; if \fBgetprotobyname_r\fP() fails with the error
105 \fBERANGE\fP, the program retries with larger buffer sizes. The following
106 shell session shows a couple of sample runs:
110 $\fB ./a.out tcp 1\fP
111 ERANGE! Retrying with larger buffer
112 getprotobyname_r() returned: 0 (success) (buflen=78)
113 p_name=tcp; p_proto=6; aliases=TCP
114 $\fB ./a.out xxx 1\fP
115 ERANGE! Retrying with larger buffer
116 getprotobyname_r() returned: 0 (success) (buflen=100)
117 Call failed/record not found
131 #define MAX_BUF 10000
134 main(int argc, char *argv[])
136 int buflen, erange_cnt, s;
137 struct protoent result_buf;
138 struct protoent *result;
143 printf("Usage: %s proto\-name [buflen]\en", argv[0]);
149 buflen = atoi(argv[2]);
151 if (buflen > MAX_BUF) {
152 printf("Exceeded buffer limit (%d)\en", MAX_BUF);
158 s = getprotobyname_r(argv[1], &result_buf,
159 buf, buflen, &result);
162 printf("ERANGE! Retrying with larger buffer\en");
165 /* Increment a byte at a time so we can see exactly
166 what size buffer was required */
170 if (buflen > MAX_BUF) {
171 printf("Exceeded buffer limit (%d)\en", MAX_BUF);
175 } while (s == ERANGE);
177 printf("getprotobyname_r() returned: %s (buflen=%d)\en",
178 (s == 0) ? "0 (success)" : (s == ENOENT) ? "ENOENT" :
179 strerror(s), buflen);
181 if (s != 0 || result == NULL) {
182 printf("Call failed/record not found\en");
186 printf("p_name=%s; p_proto=%d; aliases=",
187 result_buf.p_name, result_buf.p_proto);
188 for (p = result_buf.p_aliases; *p != NULL; p++)
196 \fBgetprotoent\fP(3), \fBprotocols\fP(5)