xref: /original-bsd/lib/libc/net/getprotoname.c (revision 4ec22e22)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)getprotoname.c	5.6 (Berkeley) 06/01/90";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <netdb.h>
13 
14 extern int _proto_stayopen;
15 
16 struct protoent *
17 getprotobyname(name)
18 	register char *name;
19 {
20 	register struct protoent *p;
21 	register char **cp;
22 
23 	setprotoent(_proto_stayopen);
24 	while (p = getprotoent()) {
25 		if (strcmp(p->p_name, name) == 0)
26 			break;
27 		for (cp = p->p_aliases; *cp != 0; cp++)
28 			if (strcmp(*cp, name) == 0)
29 				goto found;
30 	}
31 found:
32 	if (!_proto_stayopen)
33 		endprotoent();
34 	return (p);
35 }
36