1145519Sdarrenr/*	$FreeBSD$	*/
2145510Sdarrenr
3170268Sdarrenr/*
4255332Scy * Copyright (C) 2012 by Darren Reed.
5255332Scy *
6255332Scy * See the IPFILTER.LICENCE file for details on licencing.
7255332Scy *
8255332Scy * $Id$
9255332Scy */
10170268Sdarrenr
11145510Sdarrenr#include "ipf.h"
12255332Scy#include <ctype.h>
13145510Sdarrenr
14145510Sdarrenrint getproto(name)
15255332Scy	char *name;
16145510Sdarrenr{
17145510Sdarrenr	struct protoent *p;
18145510Sdarrenr	char *s;
19145510Sdarrenr
20145510Sdarrenr	for (s = name; *s != '\0'; s++)
21145510Sdarrenr		if (!ISDIGIT(*s))
22145510Sdarrenr			break;
23145510Sdarrenr	if (*s == '\0')
24145510Sdarrenr		return atoi(name);
25145510Sdarrenr
26153881Sguido#ifdef _AIX51
27153881Sguido	/*
28153881Sguido	 * For some bogus reason, "ip" is 252 in /etc/protocols on AIX 5
29255332Scy	 * The IANA has doubled up on the definition of 0 - it is now also
30255332Scy	 * used for IPv6 hop-opts, so we can no longer rely on /etc/protocols
31255332Scy	 * providing the correct name->number mapping
32153881Sguido	 */
33255332Scy#endif
34153881Sguido	if (!strcasecmp(name, "ip"))
35153881Sguido		return 0;
36153881Sguido
37145510Sdarrenr	p = getprotobyname(name);
38145510Sdarrenr	if (p != NULL)
39145510Sdarrenr		return p->p_proto;
40145510Sdarrenr	return -1;
41145510Sdarrenr}
42