.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
-.TH GETPROTOENT_R 3 2010-09-10 "GNU" "Linux Programmer's Manual"
+.TH GETPROTOENT_R 3 2019-03-06 "GNU" "Linux Programmer's Manual"
.SH NAME
getprotoent_r, getprotobyname_r, getprotobynumber_r \- get
protocol entry (reentrant)
.SH SYNOPSIS
.nf
.B #include <netdb.h>
-.sp
+.PP
.BI "int getprotoent_r(struct protoent *" result_buf ", char *" buf ,
.BI " size_t " buflen ", struct protoent **" result );
-.sp
+.PP
.BI "int getprotobyname_r(const char *" name ,
.BI " struct protoent *" result_buf ", char *" buf ,
.BI " size_t " buflen ", struct protoent **" result );
-.sp
+.PP
.BI "int getprotobynumber_r(int " proto ,
.BI " struct protoent *" result_buf ", char *" buf ,
.BI " size_t " buflen ", struct protoent **" result );
-.sp
+.PP
.fi
.in -4n
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.ad l
.in
-.sp
+.PP
.BR getprotoent_r (),
.BR getprotobyname_r (),
.BR getprotobynumber_r ():
-.RS 4
-_BSD_SOURCE || _SVID_SOURCE
-.RE
+ Since glibc 2.19:
+ _DEFAULT_SOURCE
+ Glibc 2.19 and earlier:
+ _BSD_SOURCE || _SVID_SOURCE
.ad b
.SH DESCRIPTION
The
and in the function calling signature and return value.
This manual page describes just the differences from
the nonreentrant functions.
-
+.PP
Instead of returning a pointer to a statically allocated
.I protoent
structure as the function result,
these functions copy the structure into the location pointed to by
.IR result_buf .
-
+.PP
The
.I buf
array is used to store the string fields pointed to by the returned
.\" 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
-
+.PP
If the function call successfully obtains a protocol record, then
.I *result
is set pointing to
.SH RETURN VALUE
On success, these functions return 0.
On error, they return one of the positive error numbers listed in ERRORS.
-
+.PP
On error, record not found
.RB ( getprotobyname_r (),
.BR getprotobynumber_r ()),
Try again with a larger buffer
(and increased
.IR buflen ).
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lbw20 lb lb
+l l l.
+Interface Attribute Value
+T{
+.BR getprotoent_r (),
+.br
+.BR getprotobyname_r (),
+.br
+.BR getprotobynumber_r ()
+T} Thread safety MT-Safe locale
+.TE
+.sp 1
.SH CONFORMING TO
These functions are GNU extensions.
Functions with similar names exist on some other systems,
.BR ERANGE ,
the program retries with larger buffer sizes.
The following shell session shows a couple of sample runs:
+.PP
.in +4n
-.nf
-
+.EX
.RB "$" " ./a.out tcp 1"
ERANGE! Retrying with larger buffer
getprotobyname_r() returned: 0 (success) (buflen=78)
ERANGE! Retrying with larger buffer
getprotobyname_r() returned: 0 (success) (buflen=100)
Call failed/record not found
-.fi
+.EE
.in
.SS Program source
\&
-.nf
+.EX
#define _GNU_SOURCE
#include <ctype.h>
#include <netdb.h>
char **p;
if (argc < 2) {
- printf("Usage: %s proto\-name [buflen]\\n", argv[0]);
+ printf("Usage: %s proto\-name [buflen]\en", argv[0]);
exit(EXIT_FAILURE);
}
buflen = atoi(argv[2]);
if (buflen > MAX_BUF) {
- printf("Exceeded buffer limit (%d)\\n", MAX_BUF);
+ printf("Exceeded buffer limit (%d)\en", MAX_BUF);
exit(EXIT_FAILURE);
}
buf, buflen, &result);
if (s == ERANGE) {
if (erange_cnt == 0)
- printf("ERANGE! Retrying with larger buffer\\n");
+ printf("ERANGE! Retrying with larger buffer\en");
erange_cnt++;
/* Increment a byte at a time so we can see exactly
buflen++;
if (buflen > MAX_BUF) {
- printf("Exceeded buffer limit (%d)\\n", MAX_BUF);
+ printf("Exceeded buffer limit (%d)\en", MAX_BUF);
exit(EXIT_FAILURE);
}
}
} while (s == ERANGE);
- printf("getprotobyname_r() returned: %s (buflen=%d)\\n",
+ 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\\n");
+ printf("Call failed/record not found\en");
exit(EXIT_FAILURE);
}
result_buf.p_name, result_buf.p_proto);
for (p = result_buf.p_aliases; *p != NULL; p++)
printf("%s ", *p);
- printf("\\n");
+ printf("\en");
exit(EXIT_SUCCESS);
}
-.fi
+.EE
.SH SEE ALSO
.BR getprotoent (3),
.BR protocols (5)