GETSERVENT(3N) GETSERVENT(3N) NAME getservent, getservent_r, fgetservent, fgetservent_r, getservbyport, getservbyport_r, getservbyname, getservbyname_r, setservent, endservent - get service entry SYNOPSIS #include <netdb.h> struct servent *getservent(void); struct servent *getservent_r(struct servent *entry, char *buffer, int bufsize); struct servent *fgetservent(FILE *); struct servent *fgetservent_r(FILE *, struct servent *entry, char *buffer, int bufsize); struct servent *getservbyname(const char *name, const char *proto); struct servent *getservbyname_r(const char *name, const char *proto, struct servent *entry, char *buffer, int bufsize); struct servent *getservbyport(int port, const char *proto); struct servent *getservbyport_r(int port, const char *proto, struct servent *entry, char *buffer, int bufsize); void setservent(int stayopen); void endservent(void); DESCRIPTION getservent, getservbyname, getservbyport and their reentrant counterparts each return a pointer to an object with the following structure containing the broken-out fields of a line in the file /etc/services, or some other back-end database. struct servent { char *s_name; /* official name of service */ char **s_aliases; /* alias list */ int s_port; /* port service resides at */ char *s_proto; /* protocol to use */ }; The members of this structure are: s_name The official name of the service. s_aliases A zero terminated list of alternate names for the service. s_port The port number at which the service resides. Port numbers are returned as a 16-bit value in network byte order. s_proto The name of the protocol to use when contacting the service. Getservent reads the next line of the file, opening the file if necessary. Setservent opens and rewinds the file. If the stayopen flag is non-zero, the net data base will not be closed after each call to getservbyname or getservbyport. Endservent closes the file. Getservbyname and getservbyport sequentially search from the beginning of the file until a matching protocol name or port number is found, or until EOF is encountered. If a protocol name is also supplied (non-NULL), searches must also match the protocol. The routines fgetservent and fgetservent_r return the next entry from the supplied stream as a struct servent structure. The stream must be of the same format as the file /etc/services. The functions getservent, fgetservent, getservbyname and getservbyport all return results in static memory which are overwritten on each call. Reentrant versions of each of these routines getservent_r, fgetservent_t, getservbyname_r and getservbyport_r are provided to parse the results into supplied memory. They take three extra arguments, a pointer to a struct servent structure, a pointer to a character buffer, and a length for the buffer. The functions presented in this manual page only parse files of the format given in services(4). Other back-end databases and protocols, such as NIS, can be supplied by the nsd(1M) daemon as specified in the nsd configuration file /etc/nsswitch.conf. NOTE The Mips ABI specifies nothing but local files so applications which wish to use anything else must compile with libc prior to libnsl in the library list. When nsd is running changes in the local services file may not be noticed by getservent() until the enumeration cache file has timed out. DIAGNOSTICS All functions that return struct servent * will return a null (0) pointer in the case of EOF or failure. FILES /etc/services /etc/nsswitch.conf /var/ns/cache/services.byname.m /var/ns/cache/services.byport.m SEE ALSO nsd(1M), getprotoent(3N), services(4) DIAGNOSTICS Null pointer (0) returned on EOF or error. BUGS Expecting port numbers to fit in a 32-bit quantity is probably naive. Page 3