aboutsummaryrefslogtreecommitdiff
path: root/sbin/ipf/libipf/getproto.c
blob: 4d3f2d9e1ea20475854ef8a7474503816878f5f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*	$FreeBSD$	*/

/*
 * Copyright (C) 2012 by Darren Reed.
 *
 * See the IPFILTER.LICENCE file for details on licencing.
 *
 * $Id$
 */

#include "ipf.h"
#include <ctype.h>

int getproto(char *name);

int
getproto(char *name)
{
	struct protoent *p;
	char *s;

	for (s = name; *s != '\0'; s++)
		if (!ISDIGIT(*s))
			break;
	if (*s == '\0')
		return (atoi(name));

	if (!strcasecmp(name, "ip"))
		return (0);

	p = getprotobyname(name);
	if (p != NULL)
		return (p->p_proto);
	return (-1);
}