]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/getprotoent_r.3
stdarg.3: SEE ALSO: add vprintf(3), vscanf(3), vsyslog(3)
[thirdparty/man-pages.git] / man3 / getprotoent_r.3
CommitLineData
ca1a4bba
MK
1.\" Copyright 2008, Linux Foundation, written by Michael Kerrisk
2.\" <mtk.manpages@gmail.com>
3.\"
93015253 4.\" %%%LICENSE_START(VERBATIM)
ca1a4bba
MK
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.
4b72fb64 24.\" %%%LICENSE_END
ca1a4bba 25.\"
9ba01802 26.TH GETPROTOENT_R 3 2019-03-06 "GNU" "Linux Programmer's Manual"
ca1a4bba
MK
27.SH NAME
28getprotoent_r, getprotobyname_r, getprotobynumber_r \- get
29protocol entry (reentrant)
30.SH SYNOPSIS
31.nf
32.B #include <netdb.h>
68e4db0a 33.PP
ca1a4bba
MK
34.BI "int getprotoent_r(struct protoent *" result_buf ", char *" buf ,
35.BI " size_t " buflen ", struct protoent **" result );
68e4db0a 36.PP
ca1a4bba
MK
37.BI "int getprotobyname_r(const char *" name ,
38.BI " struct protoent *" result_buf ", char *" buf ,
39.BI " size_t " buflen ", struct protoent **" result );
68e4db0a 40.PP
ca1a4bba
MK
41.BI "int getprotobynumber_r(int " proto ,
42.BI " struct protoent *" result_buf ", char *" buf ,
43.BI " size_t " buflen ", struct protoent **" result );
68e4db0a 44.PP
ca1a4bba
MK
45.fi
46.in -4n
47Feature Test Macro Requirements for glibc (see
48.BR feature_test_macros (7)):
49.ad l
50.in
68e4db0a 51.PP
ca1a4bba
MK
52.BR getprotoent_r (),
53.BR getprotobyname_r (),
54.BR getprotobynumber_r ():
51c612fb
MK
55 Since glibc 2.19:
56 _DEFAULT_SOURCE
57 Glibc 2.19 and earlier:
58 _BSD_SOURCE || _SVID_SOURCE
ca1a4bba
MK
59.ad b
60.SH DESCRIPTION
61The
62.BR getprotoent_r (),
63.BR getprotobyname_r (),
64and
65.BR getprotobynumber_r ()
66functions are the reentrant equivalents of, respectively,
67.BR getprotoent (3),
68.BR getprotobyname (3),
69and
70.BR getprotobynumber (3).
71They differ in the way that the
72.I protoent
73structure is returned,
74and in the function calling signature and return value.
75This manual page describes just the differences from
54d75d6c 76the nonreentrant functions.
847e0d88 77.PP
ca1a4bba
MK
78Instead of returning a pointer to a statically allocated
79.I protoent
80structure as the function result,
81these functions copy the structure into the location pointed to by
82.IR result_buf .
847e0d88 83.PP
ca1a4bba
MK
84The
85.I buf
86array is used to store the string fields pointed to by the returned
87.I protoent
88structure.
54d75d6c 89(The nonreentrant functions allocate these strings in static storage.)
ca1a4bba
MK
90The size of this array is specified in
91.IR buflen .
92If
93.I buf
94is too small, the call fails with the error
95.BR ERANGE ,
96and the caller must try again with a larger buffer.
97(A buffer of length 1024 bytes should be sufficient for most applications.)
98.\" I can find no information on the required/recommended buffer size;
54d75d6c 99.\" the nonreentrant functions use a 1024 byte buffer.
ca1a4bba 100.\" The 1024 byte value is also what the Solaris man page suggests. -- mtk
847e0d88 101.PP
ca1a4bba
MK
102If the function call successfully obtains a protocol record, then
103.I *result
104is set pointing to
105.IR result_buf ;
106otherwise,
107.I *result
108is set to NULL.
47297adb 109.SH RETURN VALUE
ca1a4bba 110On success, these functions return 0.
535f0df5 111On error, they return one of the positive error numbers listed in ERRORS.
847e0d88 112.PP
ca1a4bba
MK
113On error, record not found
114.RB ( getprotobyname_r (),
115.BR getprotobynumber_r ()),
116or end of input
117.RB ( getprotoent_r ())
118.I result
119is set to NULL.
120.SH ERRORS
121.TP
122.B ENOENT
123.RB ( getprotoent_r ())
124No more records in database.
125.TP
126.B ERANGE
127.I buf
128is too small.
129Try again with a larger buffer
130(and increased
131.IR buflen ).
252c5d6b
ZL
132.SH ATTRIBUTES
133For an explanation of the terms used in this section, see
134.BR attributes (7).
135.TS
136allbox;
b1c3107a 137lbw20 lb lb
252c5d6b
ZL
138l l l.
139Interface Attribute Value
140T{
141.BR getprotoent_r (),
142.br
143.BR getprotobyname_r (),
144.br
145.BR getprotobynumber_r ()
146T} Thread safety MT-Safe locale
147.TE
847e0d88 148.sp 1
47297adb 149.SH CONFORMING TO
ca1a4bba
MK
150These functions are GNU extensions.
151Functions with similar names exist on some other systems,
152though typically with different calling signatures.
153.SH EXAMPLE
154The program below uses
155.BR getprotobyname_r ()
156to retrieve the protocol record for the protocol named
157in its first command-line argument.
158If a second (integer) command-line argument is supplied,
159it is used as the initial value for
160.IR buflen ;
161if
162.BR getprotobyname_r ()
163fails with the error
164.BR ERANGE ,
165the program retries with larger buffer sizes.
166The following shell session shows a couple of sample runs:
e646a1ba 167.PP
ca1a4bba 168.in +4n
e646a1ba 169.EX
b43a3b30 170.RB "$" " ./a.out tcp 1"
ca1a4bba
MK
171ERANGE! Retrying with larger buffer
172getprotobyname_r() returned: 0 (success) (buflen=78)
173p_name=tcp; p_proto=6; aliases=TCP
b43a3b30 174.RB "$" " ./a.out xxx 1"
ca1a4bba
MK
175ERANGE! Retrying with larger buffer
176getprotobyname_r() returned: 0 (success) (buflen=100)
177Call failed/record not found
b8302363 178.EE
ca1a4bba 179.in
9c330504 180.SS Program source
d84d0300 181\&
e7d0bb47 182.EX
ca1a4bba
MK
183#define _GNU_SOURCE
184#include <ctype.h>
185#include <netdb.h>
186#include <stdlib.h>
187#include <stdio.h>
188#include <errno.h>
189#include <string.h>
190
191#define MAX_BUF 10000
192
193int
194main(int argc, char *argv[])
195{
196 int buflen, erange_cnt, s;
197 struct protoent result_buf;
198 struct protoent *result;
199 char buf[MAX_BUF];
200 char **p;
201
202 if (argc < 2) {
d1a71985 203 printf("Usage: %s proto\-name [buflen]\en", argv[0]);
ca1a4bba
MK
204 exit(EXIT_FAILURE);
205 }
206
207 buflen = 1024;
208 if (argc > 2)
209 buflen = atoi(argv[2]);
210
211 if (buflen > MAX_BUF) {
d1a71985 212 printf("Exceeded buffer limit (%d)\en", MAX_BUF);
ca1a4bba
MK
213 exit(EXIT_FAILURE);
214 }
215
216 erange_cnt = 0;
217 do {
218 s = getprotobyname_r(argv[1], &result_buf,
219 buf, buflen, &result);
220 if (s == ERANGE) {
221 if (erange_cnt == 0)
d1a71985 222 printf("ERANGE! Retrying with larger buffer\en");
ca1a4bba
MK
223 erange_cnt++;
224
225 /* Increment a byte at a time so we can see exactly
226 what size buffer was required */
227
228 buflen++;
229
230 if (buflen > MAX_BUF) {
d1a71985 231 printf("Exceeded buffer limit (%d)\en", MAX_BUF);
ca1a4bba
MK
232 exit(EXIT_FAILURE);
233 }
234 }
235 } while (s == ERANGE);
236
d1a71985 237 printf("getprotobyname_r() returned: %s (buflen=%d)\en",
ca1a4bba
MK
238 (s == 0) ? "0 (success)" : (s == ENOENT) ? "ENOENT" :
239 strerror(s), buflen);
240
241 if (s != 0 || result == NULL) {
d1a71985 242 printf("Call failed/record not found\en");
ca1a4bba
MK
243 exit(EXIT_FAILURE);
244 }
245
246 printf("p_name=%s; p_proto=%d; aliases=",
247 result_buf.p_name, result_buf.p_proto);
248 for (p = result_buf.p_aliases; *p != NULL; p++)
249 printf("%s ", *p);
d1a71985 250 printf("\en");
ca1a4bba
MK
251
252 exit(EXIT_SUCCESS);
253}
e7d0bb47 254.EE
47297adb 255.SH SEE ALSO
ca1a4bba 256.BR getprotoent (3),
ca1a4bba 257.BR protocols (5)