xref: /illumos-gate/usr/src/cmd/ipf/lib/getproto.c (revision fb876f9607a4e506a871e6b539d75c9644a3566f)
1 /*
2  * Copyright (C) 1993-2005  by Darren Reed.
3  * See the IPFILTER.LICENCE file for details on licencing.
4  */
5 
6 #include "ipf.h"
7 
8 int getproto(name)
9 char *name;
10 {
11 	struct protoent *p;
12 	char *s;
13 
14 	for (s = name; *s != '\0'; s++)
15 		if (!ISDIGIT(*s))
16 			break;
17 	if (*s == '\0')
18 		return atoi(name);
19 
20 #ifdef _AIX51
21 	/*
22 	 * For some bogus reason, "ip" is 252 in /etc/protocols on AIX 5
23 	 */
24 	if (!strcasecmp(name, "ip"))
25 		return 0;
26 #endif
27 
28 	p = getprotobyname(name);
29 	if (p != NULL)
30 		return p->p_proto;
31 	return -1;
32 }
33