getproto.c revision 255332
1/* $FreeBSD: head/contrib/ipfilter/lib/getproto.c 255332 2013-09-06 23:11:19Z cy $ */ 2 3/* 4 * Copyright (C) 2012 by Darren Reed. 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 * 8 * $Id$ 9 */ 10 11#include "ipf.h" 12#include <ctype.h> 13 14int getproto(name) 15 char *name; 16{ 17 struct protoent *p; 18 char *s; 19 20 for (s = name; *s != '\0'; s++) 21 if (!ISDIGIT(*s)) 22 break; 23 if (*s == '\0') 24 return atoi(name); 25 26#ifdef _AIX51 27 /* 28 * For some bogus reason, "ip" is 252 in /etc/protocols on AIX 5 29 * The IANA has doubled up on the definition of 0 - it is now also 30 * used for IPv6 hop-opts, so we can no longer rely on /etc/protocols 31 * providing the correct name->number mapping 32 */ 33#endif 34 if (!strcasecmp(name, "ip")) 35 return 0; 36 37 p = getprotobyname(name); 38 if (p != NULL) 39 return p->p_proto; 40 return -1; 41} 42