/// <summary> /// Checkes whether this rule matches a given frame. /// </summary> /// <param name="frame">The original frame</param> /// <param name="ethFrame">The Ethernet part of the frame</param> /// <param name="ipv4Frame">The IPv4 part of the frame</param> /// <param name="udpFrame">The UDP part of the frame</param> /// <param name="tcpFrame">The TCP part of the frame</param> /// <returns>A bool indicating whether this rule matches a given frame.</returns> public override bool IsMatch(Frame frame, eExNetworkLibrary.Ethernet.EthernetFrame ethFrame, eExNetworkLibrary.IP.IPFrame ipFrame, eExNetworkLibrary.UDP.UDPFrame udpFrame, eExNetworkLibrary.TCP.TCPFrame tcpFrame) { bool bResult; int iFrameSourcePort = 0; int iFrameDestinationPort = 0; if ((this.tProtocol == TransportProtocol.Any || this.tProtocol == TransportProtocol.TCP) && tcpFrame != null) { iFrameDestinationPort = tcpFrame.DestinationPort; iFrameSourcePort = tcpFrame.SourcePort; } else if ((this.tProtocol == TransportProtocol.Any || this.tProtocol == TransportProtocol.TCP) && udpFrame != null) { iFrameSourcePort = udpFrame.SourcePort; iFrameDestinationPort = udpFrame.DestinationPort; } else { return(false); //We have no TCP/UDP frame. } if (iPort != -1) { //Single port match bResult = iPort == iFrameDestinationPort || iPort == iFrameSourcePort; } else { bResult = (iSourcePort == -1 || iSourcePort == iFrameSourcePort) && (iDestinationPort == -1 || iDestinationPort == iFrameDestinationPort); } return(bResult && base.IsMatch(frame, ethFrame, ipFrame, udpFrame, tcpFrame)); }
/// <summary> /// Checkes whether this rule matches a given frame. /// </summary> /// <param name="frame">The original frame</param> /// <param name="ethFrame">The Ethernet part of the frame</param> /// <param name="ipv4Frame">The IPv4 part of the frame</param> /// <param name="udpFrame">The UDP part of the frame</param> /// <param name="tcpFrame">The TCP part of the frame</param> /// <returns>A bool indicating whether this rule matches a given frame.</returns> public override bool IsMatch(Frame frame, eExNetworkLibrary.Ethernet.EthernetFrame ethFrame, eExNetworkLibrary.IP.IPFrame ipFrame, eExNetworkLibrary.UDP.UDPFrame udpFrame, eExNetworkLibrary.TCP.TCPFrame tcpFrame) { if (ipFrame != null) { bool bResult; if (ipaAddress != null) { bResult = Match(ipFrame.SourceAddress, ipaAddress, smWildcard) || Match(ipFrame.DestinationAddress, ipaAddress, smWildcard); } else { bResult = Match(ipFrame.SourceAddress, ipaSource, smSourceWildcard) && Match(ipFrame.DestinationAddress, ipaDestination, smDestinationWildcard); } return(bResult && base.IsMatch(frame, ethFrame, ipFrame, udpFrame, tcpFrame)); } return(false); }