1/* $NetBSD: getproto.c,v 1.8 2012/02/15 17:55:06 riz Exp $ */ 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.5 2009/12/27 06:58:06 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 * The IANA has doubled up on the definition of 0 - it is now also 29 * used for IPv6 hop-opts, so we can no longer rely on /etc/protocols 30 * providing the correct name->number mapping 31 */ 32#endif 33 if (!strcasecmp(name, "ip")) 34 return 0; 35 36 p = getprotobyname(name); 37 if (p != NULL) 38 return p->p_proto; 39 return -1; 40} 41