161150Sbostic.\" Copyright (c) 1983, 1991, 1993 261150Sbostic.\" The Regents of the University of California. All rights reserved. 320528Smckusick.\" 443572Strent.\" %sccs.include.redist.man% 520528Smckusick.\" 6*69689Smckusick.\" @(#)getservent.3 8.4 (Berkeley) 05/25/95 736747Sbostic.\" 848352Scael.Dd 948352Scael.Dt GETSERVENT 3 1048352Scael.Os BSD 4.2 1148352Scael.Sh NAME 1248352Scael.Nm getservent , 1348352Scael.Nm getservbyport , 1448352Scael.Nm getservbyname , 1548352Scael.Nm setservent , 1648352Scael.Nm endservent 1748352Scael.Nd get service entry 1848352Scael.Sh SYNOPSIS 1948352Scael.Fd #include <netdb.h> 2048352Scael.Ft struct servent * 2148352Scael.Fn getservent 2248352Scael.Ft struct servent * 2348352Scael.Fn getservbyname "char *name" "char *proto" 2448352Scael.Ft struct servent * 2548352Scael.Fn getservbyport "int port" proto 2648352Scael.Ft void 2748352Scael.Fn setservent "int stayopen" 2848352Scael.Ft void 2948352Scael.Fn endservent void 3048352Scael.Sh DESCRIPTION 3148352ScaelThe 3248352Scael.Fn getservent , 3348352Scael.Fn getservbyname , 3420528Smckusickand 3548352Scael.Fn getservbyport 3648352Scaelfunctions 3720528Smckusickeach return a pointer to an object with the 3820528Smckusickfollowing structure 3920528Smckusickcontaining the broken-out 4020528Smckusickfields of a line in the network services data base, 4148352Scael.Pa /etc/services . 4248352Scael.Bd -literal -offset indent 4320528Smckusickstruct servent { 4420528Smckusick char *s_name; /* official name of service */ 4520528Smckusick char **s_aliases; /* alias list */ 4627925Slepreau int s_port; /* port service resides at */ 4720528Smckusick char *s_proto; /* protocol to use */ 4820528Smckusick}; 4948352Scael.Ed 5048352Scael.Pp 5120528SmckusickThe members of this structure are: 5248352Scael.Bl -tag -width s_aliases 5348352Scael.It Fa s_name 5420528SmckusickThe official name of the service. 5548352Scael.It Fa s_aliases 56*69689SmckusickA NULL-terminated list of alternate names for the service. 5748352Scael.It Fa s_port 5820528SmckusickThe port number at which the service resides. 5920528SmckusickPort numbers are returned in network byte order. 6048352Scael.It Fa s_proto 6120528SmckusickThe name of the protocol to use when contacting the 6220528Smckusickservice. 6348352Scael.El 6448352Scael.Pp 6548352ScaelThe 6648352Scael.Fn getservent 6748352Scaelfunction 6820528Smckusickreads the next line of the file, opening the file if necessary. 6948352Scael.Pp 7048352ScaelThe 7148352Scael.Fn setservent 7248352Scaelfunction 7320528Smckusickopens and rewinds the file. If the 7448352Scael.Fa stayopen 7520528Smckusickflag is non-zero, 7620528Smckusickthe net data base will not be closed after each call to 7748352Scael.Fn getservbyname 7848352Scaelor 7948352Scael.Fn getservbyport . 8048352Scael.Pp 8148352ScaelThe 8248352Scael.Fn endservent 8348352Scaelfunction 8420528Smckusickcloses the file. 8548352Scael.Pp 8648352ScaelThe 8748352Scael.Fn getservbyname 8820528Smckusickand 8948352Scael.Fn getservbyport 9048352Scaelfunctions 9120528Smckusicksequentially search from the beginning 9220528Smckusickof the file until a matching 9320528Smckusickprotocol name or 9420528Smckusickport number is found, 9548352Scaelor until 9648352Scael.Dv EOF 9748352Scaelis encountered. 98*69689SmckusickIf a protocol name is also supplied (non-\c 9948352Scael.Dv NULL ) , 10020528Smckusicksearches must also match the protocol. 10165705Smckusick.ne 1i 10248352Scael.Sh FILES 10348352Scael.Bl -tag -width /etc/services -compact 10448352Scael.It Pa /etc/services 10548352Scael.El 10648352Scael.Sh DIAGNOSTICS 10720528SmckusickNull pointer 10848352Scael(0) returned on 10948352Scael.Dv EOF 11048352Scaelor error. 11148352Scael.Sh SEE ALSO 11248352Scael.Xr getprotoent 3 , 11348352Scael.Xr services 5 11448352Scael.Sh HISTORY 11548352ScaelThe 11648352Scael.Fn getservent , 11748352Scael.Fn getservbyport , 11848352Scael.Fn getservbyname , 11948352Scael.Fn setservent , 12048352Scaeland 12148352Scael.Fn endservent 12248352Scaelfunctions appeared in 12348352Scael.Bx 4.2 . 12448352Scael.Sh BUGS 12548352ScaelThese functions use static data storage; 12648352Scaelif the data is needed for future use, it should be 12748352Scaelcopied before any subsequent calls overwrite it. 12848352ScaelExpecting port numbers to fit in a 32 bit 12920528Smckusickquantity is probably naive. 130