xref: /csrg-svn/lib/libc/net/getprotoname.c (revision 42626)
121380Sdist /*
221380Sdist  * Copyright (c) 1983 Regents of the University of California.
333679Sbostic  * All rights reserved.
433679Sbostic  *
5*42626Sbostic  * %sccs.include.redist.c%
621380Sdist  */
77900Ssam 
826621Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*42626Sbostic static char sccsid[] = "@(#)getprotoname.c	5.6 (Berkeley) 06/01/90";
1033679Sbostic #endif /* LIBC_SCCS and not lint */
1121380Sdist 
127900Ssam #include <netdb.h>
137900Ssam 
1428280Slepreau extern int _proto_stayopen;
1528280Slepreau 
167900Ssam struct protoent *
178324Ssam getprotobyname(name)
187900Ssam 	register char *name;
197900Ssam {
207900Ssam 	register struct protoent *p;
217900Ssam 	register char **cp;
227900Ssam 
2328280Slepreau 	setprotoent(_proto_stayopen);
247900Ssam 	while (p = getprotoent()) {
257900Ssam 		if (strcmp(p->p_name, name) == 0)
267900Ssam 			break;
277900Ssam 		for (cp = p->p_aliases; *cp != 0; cp++)
287900Ssam 			if (strcmp(*cp, name) == 0)
297900Ssam 				goto found;
307900Ssam 	}
317900Ssam found:
3228280Slepreau 	if (!_proto_stayopen)
3328280Slepreau 		endprotoent();
347900Ssam 	return (p);
357900Ssam }
36