xref: /netbsd-src/external/bsd/ipf/dist/lib/getproto.c (revision 13885a665959c62f13a82b3caedf986eaa17aa31)
1 /*	$NetBSD: getproto.c,v 1.2 2012/07/22 14:27:36 darrenr Exp $	*/
2 
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * Id: getproto.c,v 1.1.1.2 2012/07/22 13:44:38 darrenr Exp $
9  */
10 
11 #include "ipf.h"
12 #include <ctype.h>
13 
getproto(name)14 int 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