4 * Copyright (C) 2012 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
14 int getport(fr, name, port, proto)
23 if (fr == NULL || fr->fr_type != FR_T_IPF) {
24 s = getservbyname(name, proto);
31 int portval = atoi(name);
32 if (portval < 0 || portval > 65535)
34 *port = htons((u_short)portval);
41 * Some people will use port names in rules without specifying
42 * either TCP or UDP because it is implied by the group head.
43 * If we don't know the protocol, then the best we can do here is
44 * to take either only the TCP or UDP mapping (if one or the other
45 * is missing) or make sure both of them agree.
47 if (fr->fr_proto == 0) {
48 s = getservbyname(name, "tcp");
53 s = getservbyname(name, "udp");
58 if ((p1 == 0) && (s == NULL))
67 if ((fr->fr_flx & FI_TCPUDP) != 0) {
69 * If a rule is "tcp/udp" then check that both TCP and UDP
70 * mappings for this protocol name match ports.
72 s = getservbyname(name, "tcp");
76 s = getservbyname(name, "udp");
77 if (s == NULL || s->s_port != p1)
83 p = getprotobynumber(fr->fr_proto);
84 s = getservbyname(name, p ? p->p_name : NULL);