1.\" Copyright (c) 1983, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)getservent.3 8.4 (Berkeley) 05/25/95 7.\" 8.Dd 9.Dt GETSERVENT 3 10.Os BSD 4.2 11.Sh NAME 12.Nm getservent , 13.Nm getservbyport , 14.Nm getservbyname , 15.Nm setservent , 16.Nm endservent 17.Nd get service entry 18.Sh SYNOPSIS 19.Fd #include <netdb.h> 20.Ft struct servent * 21.Fn getservent 22.Ft struct servent * 23.Fn getservbyname "char *name" "char *proto" 24.Ft struct servent * 25.Fn getservbyport "int port" proto 26.Ft void 27.Fn setservent "int stayopen" 28.Ft void 29.Fn endservent void 30.Sh DESCRIPTION 31The 32.Fn getservent , 33.Fn getservbyname , 34and 35.Fn getservbyport 36functions 37each return a pointer to an object with the 38following structure 39containing the broken-out 40fields of a line in the network services data base, 41.Pa /etc/services . 42.Bd -literal -offset indent 43struct servent { 44 char *s_name; /* official name of service */ 45 char **s_aliases; /* alias list */ 46 int s_port; /* port service resides at */ 47 char *s_proto; /* protocol to use */ 48}; 49.Ed 50.Pp 51The members of this structure are: 52.Bl -tag -width s_aliases 53.It Fa s_name 54The official name of the service. 55.It Fa s_aliases 56A NULL-terminated list of alternate names for the service. 57.It Fa s_port 58The port number at which the service resides. 59Port numbers are returned in network byte order. 60.It Fa s_proto 61The name of the protocol to use when contacting the 62service. 63.El 64.Pp 65The 66.Fn getservent 67function 68reads the next line of the file, opening the file if necessary. 69.Pp 70The 71.Fn setservent 72function 73opens and rewinds the file. If the 74.Fa stayopen 75flag is non-zero, 76the net data base will not be closed after each call to 77.Fn getservbyname 78or 79.Fn getservbyport . 80.Pp 81The 82.Fn endservent 83function 84closes the file. 85.Pp 86The 87.Fn getservbyname 88and 89.Fn getservbyport 90functions 91sequentially search from the beginning 92of the file until a matching 93protocol name or 94port number is found, 95or until 96.Dv EOF 97is encountered. 98If a protocol name is also supplied (non-\c 99.Dv NULL ) , 100searches must also match the protocol. 101.ne 1i 102.Sh FILES 103.Bl -tag -width /etc/services -compact 104.It Pa /etc/services 105.El 106.Sh DIAGNOSTICS 107Null pointer 108(0) returned on 109.Dv EOF 110or error. 111.Sh SEE ALSO 112.Xr getprotoent 3 , 113.Xr services 5 114.Sh HISTORY 115The 116.Fn getservent , 117.Fn getservbyport , 118.Fn getservbyname , 119.Fn setservent , 120and 121.Fn endservent 122functions appeared in 123.Bx 4.2 . 124.Sh BUGS 125These functions use static data storage; 126if the data is needed for future use, it should be 127copied before any subsequent calls overwrite it. 128Expecting port numbers to fit in a 32 bit 129quantity is probably naive. 130