298 lines
6.0 KiB
HTML
298 lines
6.0 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of GETSERVENT</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>GETSERVENT</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<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>
|
|
|
|
getservent, getservbyname, getservbyport, setservent, endservent -
|
|
get service entry
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/netdb.h">netdb.h</A>></B>
|
|
|
|
<B>struct servent *getservent(void);</B>
|
|
|
|
<B>struct servent *getservbyname(const char *</B><I>name</I><B>, const char *</B><I>proto</I><B>);</B>
|
|
|
|
<B>struct servent *getservbyport(int </B><I>port</I><B>, const char *</B><I>proto</I><B>);</B>
|
|
|
|
<B>void setservent(int </B><I>stayopen</I><B>);</B>
|
|
|
|
<B>void endservent(void);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>getservent</B>()
|
|
|
|
function reads the next entry from the services database (see
|
|
<B><A HREF="/cgi-bin/man/man2html?5+services">services</A></B>(5))
|
|
|
|
and returns a
|
|
<I>servent</I>
|
|
|
|
structure containing
|
|
the broken-out fields from the entry.
|
|
A connection is opened to the database if necessary.
|
|
<P>
|
|
|
|
The
|
|
<B>getservbyname</B>()
|
|
|
|
function returns a
|
|
<I>servent</I>
|
|
|
|
structure
|
|
for the entry from the database
|
|
that matches the service
|
|
<I>name</I>
|
|
|
|
using protocol
|
|
<I>proto</I>.
|
|
|
|
If
|
|
<I>proto</I>
|
|
|
|
is NULL, any protocol will be matched.
|
|
A connection is opened to the database if necessary.
|
|
<P>
|
|
|
|
The
|
|
<B>getservbyport</B>()
|
|
|
|
function returns a
|
|
<I>servent</I>
|
|
|
|
structure
|
|
for the entry from the database
|
|
that matches the port
|
|
<I>port</I>
|
|
|
|
(given in network byte order)
|
|
using protocol
|
|
<I>proto</I>.
|
|
|
|
If
|
|
<I>proto</I>
|
|
|
|
is NULL, any protocol will be matched.
|
|
A connection is opened to the database if necessary.
|
|
<P>
|
|
|
|
The
|
|
<B>setservent</B>()
|
|
|
|
function opens a connection to the database,
|
|
and sets the next entry to the first entry.
|
|
If
|
|
<I>stayopen</I>
|
|
|
|
is nonzero,
|
|
then the connection to the database
|
|
will not be closed between calls to one of the
|
|
<B>getserv*</B>()
|
|
|
|
functions.
|
|
<P>
|
|
|
|
The
|
|
<B>endservent</B>()
|
|
|
|
function closes the connection to the database.
|
|
<P>
|
|
|
|
The
|
|
<I>servent</I>
|
|
|
|
structure is defined in
|
|
<I><<A HREF="file:///usr/include/netdb.h">netdb.h</A>></I>
|
|
|
|
as follows:
|
|
<P>
|
|
|
|
|
|
|
|
struct servent {
|
|
<BR> char *s_name; /* official service name */
|
|
<BR> char **s_aliases; /* alias list */
|
|
<BR> int s_port; /* port number */
|
|
<BR> char *s_proto; /* protocol to use */
|
|
}
|
|
|
|
|
|
<P>
|
|
|
|
The members of the
|
|
<I>servent</I>
|
|
|
|
structure are:
|
|
<DL COMPACT>
|
|
<DT id="1"><I>s_name</I>
|
|
|
|
<DD>
|
|
The official name of the service.
|
|
<DT id="2"><I>s_aliases</I>
|
|
|
|
<DD>
|
|
A NULL-terminated list of alternative names for the service.
|
|
<DT id="3"><I>s_port</I>
|
|
|
|
<DD>
|
|
The port number for the service given in network byte order.
|
|
<DT id="4"><I>s_proto</I>
|
|
|
|
<DD>
|
|
The name of the protocol to use with this service.
|
|
</DL>
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
The
|
|
<B>getservent</B>(),
|
|
|
|
<B>getservbyname</B>()
|
|
|
|
and
|
|
<B>getservbyport</B>()
|
|
|
|
functions return a pointer to a
|
|
statically allocated
|
|
<I>servent</I>
|
|
|
|
structure, or NULL if an
|
|
error occurs or the end of the file is reached.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>FILES</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="5"><I>/etc/services</I>
|
|
|
|
<DD>
|
|
services database file
|
|
</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>getservent</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>
|
|
MT-Unsafe race:servent
|
|
<BR>
|
|
|
|
race:serventbuf locale
|
|
<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>getservbyname</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>
|
|
MT-Unsafe race:servbyname
|
|
<BR>
|
|
|
|
locale
|
|
<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>getservbyport</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>
|
|
MT-Unsafe race:servbyport
|
|
<BR>
|
|
|
|
locale
|
|
<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>setservent</B>(),
|
|
|
|
<BR>
|
|
|
|
<B>endservent</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>
|
|
MT-Unsafe race:servent
|
|
<BR>
|
|
|
|
locale
|
|
<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
In the above table,
|
|
<I>servent</I>
|
|
|
|
in
|
|
<I>race:servent</I>
|
|
|
|
signifies that if any of the functions
|
|
<B>setservent</B>(),
|
|
|
|
<B>getservent</B>(),
|
|
|
|
or
|
|
<B>endservent</B>()
|
|
|
|
are used in parallel in different threads of a program,
|
|
then data races could occur.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, 4.3BSD.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getnetent">getnetent</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getprotoent">getprotoent</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getservent_r">getservent_r</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+services">services</A></B>(5)
|
|
|
|
<A NAME="lbAJ"> </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="6"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="7"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="8"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="9"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="10"><A HREF="#lbAF">FILES</A><DD>
|
|
<DT id="11"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="12"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="13"><A HREF="#lbAI">SEE ALSO</A><DD>
|
|
<DT id="14"><A HREF="#lbAJ">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>
|