xref: /csrg-svn/lib/libc/net/getservbyname.c (revision 33679)
121381Sdist /*
221381Sdist  * Copyright (c) 1983 Regents of the University of California.
3*33679Sbostic  * All rights reserved.
4*33679Sbostic  *
5*33679Sbostic  * Redistribution and use in source and binary forms are permitted
6*33679Sbostic  * provided that this notice is preserved and that due credit is given
7*33679Sbostic  * to the University of California at Berkeley. The name of the University
8*33679Sbostic  * may not be used to endorse or promote products derived from this
9*33679Sbostic  * software without specific prior written permission. This software
10*33679Sbostic  * is provided ``as is'' without express or implied warranty.
1121381Sdist  */
127902Ssam 
1326622Sdonn #if defined(LIBC_SCCS) && !defined(lint)
14*33679Sbostic static char sccsid[] = "@(#)getservbyname.c	5.4 (Berkeley) 03/07/88";
15*33679Sbostic #endif /* LIBC_SCCS and not lint */
1621381Sdist 
177902Ssam #include <netdb.h>
187902Ssam 
1928280Slepreau extern int _serv_stayopen;
2028280Slepreau 
217902Ssam struct servent *
228324Ssam getservbyname(name, proto)
237902Ssam 	char *name, *proto;
247902Ssam {
257902Ssam 	register struct servent *p;
267902Ssam 	register char **cp;
277902Ssam 
2828280Slepreau 	setservent(_serv_stayopen);
297902Ssam 	while (p = getservent()) {
307902Ssam 		if (strcmp(name, p->s_name) == 0)
317902Ssam 			goto gotname;
327902Ssam 		for (cp = p->s_aliases; *cp; cp++)
337902Ssam 			if (strcmp(name, *cp) == 0)
347902Ssam 				goto gotname;
357902Ssam 		continue;
367902Ssam gotname:
377902Ssam 		if (proto == 0 || strcmp(p->s_proto, proto) == 0)
387902Ssam 			break;
397902Ssam 	}
4028280Slepreau 	if (!_serv_stayopen)
4128280Slepreau 		endservent();
427902Ssam 	return (p);
437902Ssam }
44