Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / getportproto.c
blob5c2b3027e13e8b52f2d08fb34abc2fd7ad0a3b22
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2002-2005 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 * Id: getportproto.c,v 1.2.4.4 2006/06/16 17:21:00 darrenr Exp
9 */
11 #include <ctype.h>
12 #include "ipf.h"
14 int getportproto(name, proto)
15 char *name;
16 int proto;
18 struct servent *s;
19 struct protoent *p;
21 if (ISDIGIT(*name)) {
22 int number;
23 char *s;
25 for (s = name; *s != '\0'; s++)
26 if (!ISDIGIT(*s))
27 return -1;
29 number = atoi(name);
30 if (number < 0 || number > 65535)
31 return -1;
32 return htons(number);
35 p = getprotobynumber(proto);
36 s = getservbyname(name, p ? p->p_name : NULL);
37 if (s != NULL)
38 return s->s_port;
39 return -1;