349 lines
11 KiB
HTML
349 lines
11 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of GETPROTOENT_R</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>GETPROTOENT_R</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
getprotoent_r, getprotobyname_r, getprotobynumber_r - get
|
|
protocol entry (reentrant)
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/netdb.h">netdb.h</A>></B>
|
|
|
|
<B>int getprotoent_r(struct protoent *</B><I>result_buf</I><B>, char *</B><I>buf</I><B>,</B>
|
|
<B> size_t </B><I>buflen</I><B>, struct protoent **</B><I>result</I><B>);</B>
|
|
|
|
<B>int getprotobyname_r(const char *</B><I>name</I><B>,</B>
|
|
<B> struct protoent *</B><I>result_buf</I><B>, char *</B><I>buf</I><B>,</B>
|
|
<B> size_t </B><I>buflen</I><B>, struct protoent **</B><I>result</I><B>);</B>
|
|
|
|
<B>int getprotobynumber_r(int </B><I>proto</I><B>,</B>
|
|
<B> struct protoent *</B><I>result_buf</I><B>, char *</B><I>buf</I><B>,</B>
|
|
<B> size_t </B><I>buflen</I><B>, struct protoent **</B><I>result</I><B>);</B>
|
|
|
|
</PRE>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
|
|
<P>
|
|
|
|
<B>getprotoent_r</B>(),
|
|
|
|
<B>getprotobyname_r</B>(),
|
|
|
|
<B>getprotobynumber_r</B>():
|
|
|
|
<BR> Since glibc 2.19:
|
|
<BR> _DEFAULT_SOURCE
|
|
<BR> Glibc 2.19 and earlier:
|
|
<BR> _BSD_SOURCE || _SVID_SOURCE
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>getprotoent_r</B>(),
|
|
|
|
<B>getprotobyname_r</B>(),
|
|
|
|
and
|
|
<B>getprotobynumber_r</B>()
|
|
|
|
functions are the reentrant equivalents of, respectively,
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getprotoent">getprotoent</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getprotobyname">getprotobyname</A></B>(3),
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getprotobynumber">getprotobynumber</A></B>(3).
|
|
|
|
They differ in the way that the
|
|
<I>protoent</I>
|
|
|
|
structure is returned,
|
|
and in the function calling signature and return value.
|
|
This manual page describes just the differences from
|
|
the nonreentrant functions.
|
|
<P>
|
|
|
|
Instead of returning a pointer to a statically allocated
|
|
<I>protoent</I>
|
|
|
|
structure as the function result,
|
|
these functions copy the structure into the location pointed to by
|
|
<I>result_buf</I>.
|
|
|
|
<P>
|
|
|
|
The
|
|
<I>buf</I>
|
|
|
|
array is used to store the string fields pointed to by the returned
|
|
<I>protoent</I>
|
|
|
|
structure.
|
|
(The nonreentrant functions allocate these strings in static storage.)
|
|
The size of this array is specified in
|
|
<I>buflen</I>.
|
|
|
|
If
|
|
<I>buf</I>
|
|
|
|
is too small, the call fails with the error
|
|
<B>ERANGE</B>,
|
|
|
|
and the caller must try again with a larger buffer.
|
|
(A buffer of length 1024 bytes should be sufficient for most applications.)
|
|
|
|
|
|
|
|
<P>
|
|
|
|
If the function call successfully obtains a protocol record, then
|
|
<I>*result</I>
|
|
|
|
is set pointing to
|
|
<I>result_buf</I>;
|
|
|
|
otherwise,
|
|
<I>*result</I>
|
|
|
|
is set to NULL.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success, these functions return 0.
|
|
On error, they return one of the positive error numbers listed in ERRORS.
|
|
<P>
|
|
|
|
On error, record not found
|
|
(<B>getprotobyname_r</B>(),
|
|
|
|
<B>getprotobynumber_r</B>()),
|
|
|
|
or end of input
|
|
(<B>getprotoent_r</B>())
|
|
|
|
<I>result</I>
|
|
|
|
is set to NULL.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>ENOENT</B>
|
|
|
|
<DD>
|
|
(<B>getprotoent_r</B>())
|
|
|
|
No more records in database.
|
|
<DT id="2"><B>ERANGE</B>
|
|
|
|
<DD>
|
|
<I>buf</I>
|
|
|
|
is too small.
|
|
Try again with a larger buffer
|
|
(and increased
|
|
<I>buflen</I>).
|
|
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>getprotoent_r</B>(),
|
|
|
|
<BR>
|
|
|
|
<B>getprotobyname_r</B>(),
|
|
|
|
<BR>
|
|
|
|
<B>getprotobynumber_r</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe locale<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
These functions are GNU extensions.
|
|
Functions with similar names exist on some other systems,
|
|
though typically with different calling signatures.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
The program below uses
|
|
<B>getprotobyname_r</B>()
|
|
|
|
to retrieve the protocol record for the protocol named
|
|
in its first command-line argument.
|
|
If a second (integer) command-line argument is supplied,
|
|
it is used as the initial value for
|
|
<I>buflen</I>;
|
|
|
|
if
|
|
<B>getprotobyname_r</B>()
|
|
|
|
fails with the error
|
|
<B>ERANGE</B>,
|
|
|
|
the program retries with larger buffer sizes.
|
|
The following shell session shows a couple of sample runs:
|
|
<P>
|
|
|
|
|
|
|
|
$<B> ./a.out tcp 1</B>
|
|
|
|
ERANGE! Retrying with larger buffer
|
|
getprotobyname_r() returned: 0 (success) (buflen=78)
|
|
p_name=tcp; p_proto=6; aliases=TCP
|
|
$<B> ./a.out xxx 1</B>
|
|
|
|
ERANGE! Retrying with larger buffer
|
|
getprotobyname_r() returned: 0 (success) (buflen=100)
|
|
Call failed/record not found
|
|
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H3>Program source</H3>
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
#include <<A HREF="file:///usr/include/ctype.h">ctype.h</A>>
|
|
#include <<A HREF="file:///usr/include/netdb.h">netdb.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/errno.h">errno.h</A>>
|
|
#include <<A HREF="file:///usr/include/string.h">string.h</A>>
|
|
<P>
|
|
#define MAX_BUF 10000
|
|
<P>
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
<BR> int buflen, erange_cnt, s;
|
|
<BR> struct protoent result_buf;
|
|
<BR> struct protoent *result;
|
|
<BR> char buf[MAX_BUF];
|
|
<BR> char **p;
|
|
<P>
|
|
<BR> if (argc < 2) {
|
|
<BR> printf("Usage: %s proto-name [buflen]\n", argv[0]);
|
|
<BR> exit(EXIT_FAILURE);
|
|
<BR> }
|
|
<P>
|
|
<BR> buflen = 1024;
|
|
<BR> if (argc > 2)
|
|
<BR> buflen = atoi(argv[2]);
|
|
<P>
|
|
<BR> if (buflen > MAX_BUF) {
|
|
<BR> printf("Exceeded buffer limit (%d)\n", MAX_BUF);
|
|
<BR> exit(EXIT_FAILURE);
|
|
<BR> }
|
|
<P>
|
|
<BR> erange_cnt = 0;
|
|
<BR> do {
|
|
<BR> s = getprotobyname_r(argv[1], &result_buf,
|
|
<BR> buf, buflen, &result);
|
|
<BR> if (s == ERANGE) {
|
|
<BR> if (erange_cnt == 0)
|
|
<BR> printf("ERANGE! Retrying with larger buffer\n");
|
|
<BR> erange_cnt++;
|
|
<P>
|
|
<BR> /* Increment a byte at a time so we can see exactly
|
|
<BR> what size buffer was required */
|
|
<P>
|
|
<BR> buflen++;
|
|
<P>
|
|
<BR> if (buflen > MAX_BUF) {
|
|
<BR> printf("Exceeded buffer limit (%d)\n", MAX_BUF);
|
|
<BR> exit(EXIT_FAILURE);
|
|
<BR> }
|
|
<BR> }
|
|
<BR> } while (s == ERANGE);
|
|
<P>
|
|
<BR> printf("getprotobyname_r() returned: %s (buflen=%d)\n",
|
|
<BR> (s == 0) ? "0 (success)" : (s == ENOENT) ? "ENOENT" :
|
|
<BR> strerror(s), buflen);
|
|
<P>
|
|
<BR> if (s != 0 || result == NULL) {
|
|
<BR> printf("Call failed/record not found\n");
|
|
<BR> exit(EXIT_FAILURE);
|
|
<BR> }
|
|
<P>
|
|
<BR> printf("p_name=%s; p_proto=%d; aliases=",
|
|
<BR> result_buf.p_name, result_buf.p_proto);
|
|
<BR> for (p = result_buf.p_aliases; *p != NULL; p++)
|
|
<BR> printf("%s ", *p);
|
|
<BR> printf("\n");
|
|
<P>
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getprotoent">getprotoent</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+protocols">protocols</A></B>(5)
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="3"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="4"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="5"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="6"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="7"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="8"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="9"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="10"><A HREF="#lbAI">EXAMPLE</A><DD>
|
|
<DL>
|
|
<DT id="11"><A HREF="#lbAJ">Program source</A><DD>
|
|
</DL>
|
|
<DT id="12"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="13"><A HREF="#lbAL">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:44 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|