NetBSD/dist/ipf/lib/getproto.c

41 lines
843 B
C
Raw Normal View History

/* $NetBSD: getproto.c,v 1.5 2008/05/20 07:08:07 darrenr Exp $ */
2007-04-15 00:34:18 +04:00
/*
* Copyright (C) 2002-2005 by Darren Reed.
*
* See the IPFILTER.LICENCE file for details on licencing.
*
* Id: getproto.c,v 1.2.2.4 2007/10/27 16:03:38 darrenr Exp
2007-04-15 00:34:18 +04:00
*/
2004-03-28 12:55:20 +04:00
#include "ipf.h"
int getproto(name)
char *name;
{
struct protoent *p;
char *s;
for (s = name; *s != '\0'; s++)
if (!ISDIGIT(*s))
2004-03-28 12:55:20 +04:00
break;
if (*s == '\0')
return atoi(name);
2006-04-04 20:17:18 +04:00
#ifdef _AIX51
/*
* For some bogus reason, "ip" is 252 in /etc/protocols on AIX 5
* The IANA has doubled up on the definition of 0 - it is now also
* used for IPv6 hop-opts, so we can no longer rely on /etc/protocols
* providing the correct name->number mapping
2006-04-04 20:17:18 +04:00
*/
#endif
2006-04-04 20:17:18 +04:00
if (!strcasecmp(name, "ip"))
return 0;
2004-03-28 12:55:20 +04:00
p = getprotobyname(name);
if (p != NULL)
return p->p_proto;
return -1;
}