// This method is called for each frame which is sent to the traffic handler.
        // It's the core method where all the work should be done.
        protected override void HandleTraffic(Frame fInputFrame)
        {
            //Each handler has some support methods

            // Gets the IP component of the input frame, or null, if no IP component is present.
            eExNetworkLibrary.IP.IPFrame      ipFrame   = GetIPFrame(fInputFrame);
            eExNetworkLibrary.IP.IPv4Frame    ipv4Frame = GetIPv4Frame(fInputFrame);
            eExNetworkLibrary.IP.V6.IPv6Frame ipv6Frame = GetIPv6Frame(fInputFrame);

            //This is also possible for TCP-Frames and so on
            eExNetworkLibrary.TCP.TCPFrame tcpFrame = GetTCPFrame(fInputFrame);

            //There are also some helper classes
            eExNetworkLibrary.IP.IPAddressAnalysis.GetIPRange(
                new System.Net.IPAddress(new byte[] { 192, 168, 1, 1 }),
                new System.Net.IPAddress(new byte[] { 192, 168, 1, 254 }));

            if (tcpFrame != null)
            {
                //Now, do something with the frame.
                tcpFrame.DestinationPort = 8080;

                //The payload of a frame is set in the EncapsulatedFrame property.
                //For example, an Ethernet frame has an encapsulated IPFrame, the IPFrame has
                //an encapsulated TCP frame, and the encapsulated frame of the TCP frame is
                //the payload data.
                tcpFrame.EncapsulatedFrame = null; //Delete the payload of the TCP frame

                //But don't forget to adjust checksums if you modify traffic.
                //Also you have to use the pseudo-header of the right frame
                tcpFrame.Checksum = tcpFrame.CalculateChecksum(ipFrame.GetPseudoHeader());
            }

            //Push the frame to the next handler.
            //Omit this call, if you want to discard the frame.
            NotifyNext(fInputFrame);
        }
Beispiel #2
0
 private bool IsLocal(eExNetworkLibrary.IP.IPFrame ipv4Frame)
 {
     return(lLocalAddresses.Contains(ipv4Frame.SourceAddress) || lLocalAddresses.Contains(ipv4Frame.DestinationAddress));
 }
Beispiel #3
0
        /// <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);
        }