]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/getservent.3
Note that code segments, structure definitions, shell session
[thirdparty/man-pages.git] / man3 / getservent.3
CommitLineData
fea681da
MK
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2.\"
3.\" Permission is granted to make and distribute verbatim copies of this
4.\" manual provided the copyright notice and this permission notice are
5.\" preserved on all copies.
6.\"
7.\" Permission is granted to copy and distribute modified versions of this
8.\" manual under the conditions for verbatim copying, provided that the
9.\" entire resulting derived work is distributed under the terms of a
10.\" permission notice identical to this one.
c13182ef 11.\"
fea681da
MK
12.\" Since the Linux kernel and libraries are constantly changing, this
13.\" manual page may be incorrect or out-of-date. The author(s) assume no
14.\" responsibility for errors or omissions, or for damages resulting from
15.\" the use of the information contained herein. The author(s) may not
16.\" have taken the same level of care in the production of this manual,
17.\" which is licensed free of charge, as they might when working
18.\" professionally.
c13182ef 19.\"
fea681da
MK
20.\" Formatted or processed versions of this manual, if unaccompanied by
21.\" the source, must acknowledge the copyright and authors of this work.
22.\"
23.\" References consulted:
24.\" Linux libc source code
25.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26.\" 386BSD man pages
27.\" Modified Sat Jul 24 19:19:11 1993 by Rik Faith (faith@cs.unc.edu)
28.\" Modified Wed Oct 18 20:23:54 1995 by Martin Schulze <joey@infodrom.north.de>
29.\" Modified Mon Apr 22 01:50:54 1996 by Martin Schulze <joey@infodrom.north.de>
30.\" 2001-07-25 added a clause about NULL proto (Martin Michlmayr or David N. Welton)
31.\"
69962544 32.TH GETSERVENT 3 2001-07-25 "GNU" "Linux Programmer's Manual"
fea681da
MK
33.SH NAME
34getservent, getservbyname, getservbyport, setservent, endservent \-
c13182ef 35get service entry
fea681da
MK
36.SH SYNOPSIS
37.nf
38.B #include <netdb.h>
39.sp
40.B struct servent *getservent(void);
41.sp
42.BI "struct servent *getservbyname(const char *" name ", const char *" proto );
43.sp
44.BI "struct servent *getservbyport(int " port ", const char *" proto );
45.sp
46.BI "void setservent(int " stayopen );
47.sp
48.B void endservent(void);
49.fi
50.SH DESCRIPTION
60a90ecd
MK
51The
52.BR getservent ()
53function reads the next line from the file
fea681da 54\fI/etc/services\fP and returns a structure \fIservent\fP containing
c13182ef
MK
55the broken out fields from the line.
56The \fI/etc/services\fP file
fea681da
MK
57is opened if necessary.
58.PP
60a90ecd
MK
59The
60.BR getservbyname ()
61function returns a \fIservent\fP structure
fea681da 62for the line from \fI/etc/services\fP that matches the service
1c44bd5b
MK
63\fIname\fP using protocol \fIproto\fP.
64If \fIproto\fP is NULL, any protocol will be matched.
fea681da 65.PP
60a90ecd
MK
66The
67.BR getservbyport ()
68function returns a \fIservent\fP structure
fea681da 69for the line that matches the port \fIport\fP given in network byte order
1c44bd5b
MK
70using protocol \fIproto\fP.
71If \fIproto\fP is NULL, any protocol will be matched.
fea681da 72.PP
60a90ecd
MK
73The
74.BR setservent ()
75function opens and rewinds the
c13182ef
MK
76\fI/etc/services\fP file.
77If \fIstayopen\fP is true (1), then the
60a90ecd
MK
78file will not be closed between calls to
79.BR getservbyname ()
80and
81.BR getservbyport ().
fea681da 82.PP
60a90ecd
MK
83The
84.BR endservent ()
85function closes \fI/etc/services\fP.
fea681da
MK
86.PP
87The \fIservent\fP structure is defined in \fI<netdb.h>\fP as follows:
88.sp
a08ea57c 89.RS 4
fea681da 90.nf
fea681da 91struct servent {
7295b7ed
MK
92 char *s_name; /* official service name */
93 char **s_aliases; /* alias list */
94 int s_port; /* port number */
95 char *s_proto; /* protocol to use */
fea681da 96}
fea681da
MK
97.fi
98.RE
99.PP
100The members of the \fIservent\fP structure are:
101.TP
102.I s_name
103The official name of the service.
104.TP
105.I s_aliases
106A zero terminated list of alternative names for the service.
107.TP
108.I s_port
109The port number for the service given in network byte order.
110.TP
111.I s_proto
112The name of the protocol to use with this service.
113.SH "RETURN VALUE"
60a90ecd
MK
114The
115.BR getservent (),
116.BR getservbyname ()
117and
118.BR getservbyport ()
fea681da
MK
119functions return the \fIservent\fP structure, or a NULL pointer if an
120error occurs or the end of the file is reached.
121.SH FILES
122.TP
123.I /etc/services
124services database file
125.SH "CONFORMING TO"
68e1685c 1264.3BSD, POSIX.1-2001.
fea681da
MK
127.SH "SEE ALSO"
128.BR getnetent (3),
129.BR getprotoent (3),
130.BR services (5)