4 * Copyright (C) 2002-2005 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: getport.c,v 1.1.4.6 2006/06/16 17:21:00 darrenr Exp
13 int getport(fr
, name
, port
)
22 if (fr
== NULL
|| fr
->fr_type
!= FR_T_IPF
) {
23 s
= getservbyname(name
, NULL
);
32 * Some people will use port names in rules without specifying
33 * either TCP or UDP because it is implied by the group head.
34 * If we don't know the protocol, then the best we can do here is
35 * to take either only the TCP or UDP mapping (if one or the other
36 * is missing) or make sure both of them agree.
38 if (fr
->fr_proto
== 0) {
39 s
= getservbyname(name
, "tcp");
44 s
= getservbyname(name
, "udp");
49 if ((p1
== 0) && (s
== NULL
))
58 if ((fr
->fr_flx
& FI_TCPUDP
) != 0) {
60 * If a rule is "tcp/udp" then check that both TCP and UDP
61 * mappings for this protocol name match ports.
63 s
= getservbyname(name
, "tcp");
67 s
= getservbyname(name
, "udp");
68 if (s
== NULL
|| s
->s_port
!= p1
)
74 p
= getprotobynumber(fr
->fr_proto
);
75 s
= getservbyname(name
, p
? p
->p_name
: NULL
);