xref: /csrg-svn/lib/libc/net/getservbyname.c (revision 46604)
121381Sdist /*
221381Sdist  * Copyright (c) 1983 Regents of the University of California.
333679Sbostic  * All rights reserved.
433679Sbostic  *
542626Sbostic  * %sccs.include.redist.c%
621381Sdist  */
77902Ssam 
826622Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*46604Sbostic static char sccsid[] = "@(#)getservbyname.c	5.7 (Berkeley) 02/24/91";
1033679Sbostic #endif /* LIBC_SCCS and not lint */
1121381Sdist 
127902Ssam #include <netdb.h>
13*46604Sbostic #include <string.h>
147902Ssam 
1528280Slepreau extern int _serv_stayopen;
1628280Slepreau 
177902Ssam struct servent *
188324Ssam getservbyname(name, proto)
19*46604Sbostic 	const char *name, *proto;
207902Ssam {
217902Ssam 	register struct servent *p;
227902Ssam 	register char **cp;
237902Ssam 
2428280Slepreau 	setservent(_serv_stayopen);
257902Ssam 	while (p = getservent()) {
267902Ssam 		if (strcmp(name, p->s_name) == 0)
277902Ssam 			goto gotname;
287902Ssam 		for (cp = p->s_aliases; *cp; cp++)
297902Ssam 			if (strcmp(name, *cp) == 0)
307902Ssam 				goto gotname;
317902Ssam 		continue;
327902Ssam gotname:
337902Ssam 		if (proto == 0 || strcmp(p->s_proto, proto) == 0)
347902Ssam 			break;
357902Ssam 	}
3628280Slepreau 	if (!_serv_stayopen)
3728280Slepreau 		endservent();
387902Ssam 	return (p);
397902Ssam }
40