1.\" $OpenBSD: getservent.3,v 1.11 2000/12/24 00:30:56 aaron Exp $ 2.\" 3.\" Copyright (c) 1983, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by the University of 17.\" California, Berkeley and its contributors. 18.\" 4. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.Dd January 12, 1994 35.Dt GETSERVENT 3 36.Os 37.Sh NAME 38.Nm getservent , 39.Nm getservbyport , 40.Nm getservbyname , 41.Nm setservent , 42.Nm endservent 43.Nd get service entry 44.Sh SYNOPSIS 45.Fd #include <netdb.h> 46.Ft struct servent * 47.Fn getservent "void" 48.Ft struct servent * 49.Fn getservbyname "char *name" "char *proto" 50.Ft struct servent * 51.Fn getservbyport "int port" "char *proto" 52.Ft void 53.Fn setservent "int stayopen" 54.Ft void 55.Fn endservent "void" 56.Sh DESCRIPTION 57The 58.Fn getservent , 59.Fn getservbyname , 60and 61.Fn getservbyport 62functions each return a pointer to an object with the following structure 63containing the broken-out fields of a line in the network services database, 64.Pa /etc/services . 65.Bd -literal -offset indent 66struct servent { 67 char *s_name; /* official name of service */ 68 char **s_aliases; /* alias list */ 69 int s_port; /* port service resides at */ 70 char *s_proto; /* protocol to use */ 71}; 72.Ed 73.Pp 74The members of this structure are: 75.Bl -tag -width s_aliases 76.It Fa s_name 77The official name of the service. 78.It Fa s_aliases 79A zero-terminated list of alternate names for the service. 80.It Fa s_port 81The port number at which the service resides. 82Port numbers are returned in network byte order. 83.It Fa s_proto 84The name of the protocol to use when contacting the service. 85.El 86.Pp 87The 88.Fn getservent 89function reads the next line of the file, opening the file if necessary. 90.Pp 91The 92.Fn setservent 93function opens and rewinds the file. 94If the 95.Fa stayopen 96flag is non-zero, 97the net database will not be closed after each call to 98.Fn getservbyname 99or 100.Fn getservbyport . 101.Pp 102The 103.Fn endservent 104function closes the file. 105.Pp 106The 107.Fn getservbyname 108and 109.Fn getservbyport 110functions sequentially search from the beginning of the file until a 111matching protocol name or port number (specified in network byte order) 112is found, or until 113.Dv EOF 114is encountered. 115If a protocol name is also supplied (non-null), 116searches must also match the protocol. 117.Sh FILES 118.Bl -tag -width /etc/services -compact 119.It Pa /etc/services 120.El 121.Sh DIAGNOSTICS 122Null pointer (0) returned on 123.Dv EOF 124or error. 125.Sh SEE ALSO 126.Xr getprotoent 3 , 127.Xr services 5 128.Sh HISTORY 129The 130.Fn getservent , 131.Fn getservbyport , 132.Fn getservbyname , 133.Fn setservent , 134and 135.Fn endservent 136functions appeared in 137.Bx 4.2 . 138.Sh BUGS 139These functions use static data storage; if the data is needed for future use, 140it should be copied before any subsequent calls overwrite it. 141Expecting port numbers to fit in a 32-bit quantity is probably naive. 142