Move /var/svc/log to /var/log/svc
[unleashed/lotheac.git] / usr / src / cmd / ipf / lib / common / getportproto.c
blobae04229c67ef3747ee331bff52dc9f326f009072
1 /*
2 * Copyright (C) 1993-2005 by Darren Reed.
3 * See the IPFILTER.LICENCE file for details on licencing.
4 */
6 #include <ctype.h>
7 #include "ipf.h"
9 int getportproto(name, proto)
10 char *name;
11 int proto;
13 struct servent *s;
14 struct protoent *p;
16 if (ISDIGIT(*name)) {
17 int number;
18 char *s;
20 for (s = name; *s != '\0'; s++)
21 if (!ISDIGIT(*s))
22 return -1;
24 number = atoi(name);
25 if (number < 0 || number > 65535)
26 return -1;
27 return htons(number);
30 p = getprotobynumber(proto);
31 s = getservbyname(name, p ? p->p_name : NULL);
32 if (s != NULL)
33 return s->s_port;
34 return -1;