1.\" $NetBSD: getservent.3,v 1.6 1997/05/12 06:48:38 mikel 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.\" @(#)getservent.3 8.3 (Berkeley) 1/12/94 35.\" 36.Dd January 12, 1994 37.Dt GETSERVENT 3 38.Os BSD 4.2 39.Sh NAME 40.Nm getservent , 41.Nm getservbyport , 42.Nm getservbyname , 43.Nm setservent , 44.Nm endservent 45.Nd get service entry 46.Sh SYNOPSIS 47.Fd #include <netdb.h> 48.Ft struct servent * 49.Fn getservent 50.Ft struct servent * 51.Fn getservbyname "const char *name" "const char *proto" 52.Ft struct servent * 53.Fn getservbyport "int port" "const char *proto" 54.Ft void 55.Fn setservent "int stayopen" 56.Ft void 57.Fn endservent void 58.Sh DESCRIPTION 59The 60.Fn getservent , 61.Fn getservbyname , 62and 63.Fn getservbyport 64functions 65each return a pointer to an object with the 66following structure 67containing the broken-out 68fields of a line in the network services data base, 69.Pa /etc/services . 70.Bd -literal -offset indent 71struct servent { 72 char *s_name; /* official name of service */ 73 char **s_aliases; /* alias list */ 74 int s_port; /* port service resides at */ 75 char *s_proto; /* protocol to use */ 76}; 77.Ed 78.Pp 79The members of this structure are: 80.Bl -tag -width s_aliases 81.It Fa s_name 82The official name of the service. 83.It Fa s_aliases 84A zero terminated list of alternative names for the service. 85.It Fa s_port 86The port number at which the service resides. 87Port numbers must be given and are returned in network byte order. 88.It Fa s_proto 89The name of the protocol to use when contacting the 90service. 91.El 92.Pp 93The 94.Fn getservent 95function 96reads the next line of the file, opening the file if necessary. 97.Pp 98The 99.Fn setservent 100function 101opens and rewinds the file. If the 102.Fa stayopen 103flag is non-zero, 104the net data base will not be closed after each call to 105.Fn getservbyname 106or 107.Fn getservbyport . 108.Pp 109The 110.Fn endservent 111function 112closes the file. 113.Pp 114The 115.Fn getservbyname 116and 117.Fn getservbyport 118functions 119sequentially search from the beginning 120of the file until a matching 121protocol name or 122port number is found, 123or until 124.Dv EOF 125is encountered. 126If a protocol name is also supplied (non- 127.Dv NULL ) , 128searches must also match the protocol. 129.ne 1i 130.Sh FILES 131.Bl -tag -width /etc/services -compact 132.It Pa /etc/services 133.El 134.Sh DIAGNOSTICS 135Null pointer 136(0) returned on 137.Dv EOF 138or error. 139.Sh SEE ALSO 140.Xr getprotoent 3 , 141.Xr services 5 142.Sh HISTORY 143The 144.Fn getservent , 145.Fn getservbyport , 146.Fn getservbyname , 147.Fn setservent , 148and 149.Fn endservent 150functions appeared in 151.Bx 4.2 . 152.Sh BUGS 153These functions use static data storage; 154if the data is needed for future use, it should be 155copied before any subsequent calls overwrite it. 156Expecting port numbers to fit in a 32 bit 157quantity is probably naive. 158