xref: /freebsd/sbin/ipf/libipf/getproto.c (revision efeb8bffe34422937c7f8df836afb5b817366d16)
1 /*	$FreeBSD$	*/
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 
14 int getproto(char *name);
15 
16 int
17 getproto(char *name)
18 {
19 	struct protoent *p;
20 	char *s;
21 
22 	for (s = name; *s != '\0'; s++)
23 		if (!ISDIGIT(*s))
24 			break;
25 	if (*s == '\0')
26 		return atoi(name);
27 
28 	if (!strcasecmp(name, "ip"))
29 		return 0;
30 
31 	p = getprotobyname(name);
32 	if (p != NULL)
33 		return p->p_proto;
34 	return -1;
35 }
36