Move /var/svc/log to /var/log/svc
[unleashed/lotheac.git] / usr / src / cmd / ipf / lib / common / getport.c
blob415522ffc0dfc772992a3fa04e24595d92ee5e2c
1 /*
2 * Copyright (C) 1993-2005 by Darren Reed.
3 * See the IPFILTER.LICENCE file for details on licencing.
4 */
6 #include "ipf.h"
8 int getport(fr, name, port)
9 frentry_t *fr;
10 char *name;
11 u_short *port;
13 struct protoent *p;
14 struct servent *s;
15 u_short p1;
17 if (fr == NULL || fr->fr_type != FR_T_IPF) {
18 s = getservbyname(name, NULL);
19 if (s != NULL) {
20 *port = s->s_port;
21 return 0;
23 return -1;
26 if ((fr->fr_flx & FI_TCPUDP) != 0) {
28 * If a rule is "tcp/udp" then check that both TCP and UDP
29 * mappings for this protocol name match ports.
31 s = getservbyname(name, "tcp");
32 if (s == NULL)
33 return -1;
34 p1 = s->s_port;
35 s = getservbyname(name, "udp");
36 if (s == NULL || s->s_port != p1)
37 return -1;
38 *port = p1;
39 return 0;
42 p = getprotobynumber(fr->fr_proto);
43 s = getservbyname(name, p ? p->p_name : NULL);
44 if (s != NULL) {
45 *port = s->s_port;
46 return 0;
48 return -1;