xref: /csrg-svn/lib/libc/net/getprotoname.c (revision 46604)
121380Sdist /*
221380Sdist  * Copyright (c) 1983 Regents of the University of California.
333679Sbostic  * All rights reserved.
433679Sbostic  *
542626Sbostic  * %sccs.include.redist.c%
621380Sdist  */
77900Ssam 
826621Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*46604Sbostic static char sccsid[] = "@(#)getprotoname.c	5.7 (Berkeley) 02/24/91";
1033679Sbostic #endif /* LIBC_SCCS and not lint */
1121380Sdist 
127900Ssam #include <netdb.h>
13*46604Sbostic #include <string.h>
147900Ssam 
1528280Slepreau extern int _proto_stayopen;
1628280Slepreau 
177900Ssam struct protoent *
188324Ssam getprotobyname(name)
19*46604Sbostic 	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