xref: /csrg-svn/lib/libc/net/getprotoname.c (revision 61150)
121380Sdist /*
2*61150Sbostic  * Copyright (c) 1983, 1993
3*61150Sbostic  *	The Regents of the University of California.  All rights reserved.
433679Sbostic  *
542626Sbostic  * %sccs.include.redist.c%
621380Sdist  */
77900Ssam 
826621Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*61150Sbostic static char sccsid[] = "@(#)getprotoname.c	8.1 (Berkeley) 06/04/93";
1033679Sbostic #endif /* LIBC_SCCS and not lint */
1121380Sdist 
127900Ssam #include <netdb.h>
1346604Sbostic #include <string.h>
147900Ssam 
1528280Slepreau extern int _proto_stayopen;
1628280Slepreau 
177900Ssam struct protoent *
getprotobyname(name)188324Ssam getprotobyname(name)
1946604Sbostic 	register const char *name;
207900Ssam {
217900Ssam 	register struct protoent *p;
227900Ssam 	register char **cp;
237900Ssam 
2428280Slepreau 	setprotoent(_proto_stayopen);
257900Ssam 	while (p = getprotoent()) {
267900Ssam 		if (strcmp(p->p_name, name) == 0)
277900Ssam 			break;
287900Ssam 		for (cp = p->p_aliases; *cp != 0; cp++)
297900Ssam 			if (strcmp(*cp, name) == 0)
307900Ssam 				goto found;
317900Ssam 	}
327900Ssam found:
3328280Slepreau 	if (!_proto_stayopen)
3428280Slepreau 		endprotoent();
357900Ssam 	return (p);
367900Ssam }
37