getproto.c revision 170268
1/*	$FreeBSD: head/contrib/ipfilter/lib/getproto.c 170268 2007-06-04 02:54:36Z darrenr $	*/
2
3/*
4 * Copyright (C) 2002-2005 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 * $Id: getproto.c,v 1.2.2.3 2006/06/16 17:21:00 darrenr Exp $
9 */
10
11#include "ipf.h"
12
13int getproto(name)
14char *name;
15{
16	struct protoent *p;
17	char *s;
18
19	for (s = name; *s != '\0'; s++)
20		if (!ISDIGIT(*s))
21			break;
22	if (*s == '\0')
23		return atoi(name);
24
25#ifdef _AIX51
26	/*
27	 * For some bogus reason, "ip" is 252 in /etc/protocols on AIX 5
28	 */
29	if (!strcasecmp(name, "ip"))
30		return 0;
31#endif
32
33	p = getprotobyname(name);
34	if (p != NULL)
35		return p->p_proto;
36	return -1;
37}
38