]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/lib/getproto.c
zfs: merge openzfs/zfs@afa7b3484 (master) into main
[FreeBSD/FreeBSD.git] / contrib / ipfilter / lib / getproto.c
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(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         if (!strcasecmp(name, "ip"))
27                 return 0;
28
29         p = getprotobyname(name);
30         if (p != NULL)
31                 return p->p_proto;
32         return -1;
33 }