Ejemplo n.º 1
0
        void UpdateFromFilter()
        {
            if (m_filter != null)
            {
                this.Text = "Filter - " + m_filter.Name;
                checkBoxIPExcluded.Checked   = m_filter.AddressExcluded;
                checkBoxPortExcluded.Checked = m_filter.PortExluded;
                checkBoxOnlyData.Checked     = m_filter.DataOnly;
                if (m_filter.IncludedProtocol(ProtocolType.Tcp))
                {
                    checkBoxTCP.Checked = true;
                }
                if (m_filter.IncludedProtocol(ProtocolType.Udp))
                {
                    checkBoxUDP.Checked = true;
                }

                for (int i = 0; i < m_filter.AddressList.Count; i++)
                {
                    listBoxIP.Items.Add(m_filter.AddressList[i].ip.ToString() + "/"
                                        + m_filter.AddressList[i].mask.ToString());
                }

                for (int i = 0; i < m_filter.Portlist.Count; i++)
                {
                    listBoxPort.Items.Add(m_filter.Portlist[i].ToString());
                }
            }
        }
Ejemplo n.º 2
0
        bool CheckWithFilter(IPHeader ipHdr, TCPHeader tcpHdr, UDPHeader udpHdr)
        {
            if (m_filter == null)
            {
                return(true);
            }


            if (!m_filter.IncludedProtocol(ipHdr.Protocol))
            {
                return(false);
            }

            if (m_filter.AddressList.Count > 0)
            {
                IPAddress remoteAddr1 = null;
                IPAddress remoteAddr2 = null;
                if (ipHdr.DestinationAddress.Address == m_sniffingIPAddress.Address)
                {
                    remoteAddr1 = ipHdr.SourceAddress;
                }
                else if (ipHdr.SourceAddress.Address == m_sniffingIPAddress.Address)
                {
                    remoteAddr1 = ipHdr.DestinationAddress;
                }
                else
                {
                    remoteAddr1 = ipHdr.SourceAddress;
                    remoteAddr2 = ipHdr.DestinationAddress;
                }

                if (remoteAddr2 == null)
                {
                    if ((m_filter.AddressExcluded == m_filter.IncludedAddress(remoteAddr1)))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!m_filter.AddressExcluded)
                    {
                        if (!m_filter.IncludedAddress(remoteAddr1) &&
                            !m_filter.IncludedAddress(remoteAddr2))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (m_filter.IncludedAddress(remoteAddr1) ||
                            m_filter.IncludedAddress(remoteAddr2))
                        {
                            return(false);
                        }
                    }
                }
            }

            ushort destport = 0;
            ushort srcport  = 0;
            ushort msglen   = 0;

            if (tcpHdr != null)
            {
                destport = tcpHdr.DestinationPort;
                srcport  = tcpHdr.SourcePort;
                msglen   = tcpHdr.MessageLength;
            }
            else if (udpHdr != null)
            {
                destport = udpHdr.DestinationPort;
                srcport  = udpHdr.SourcePort;
                msglen   = udpHdr.MessageLength;
            }
            else
            {
                return(false);
            }

            if (m_filter.DataOnly && msglen <= 0)
            {
                return(false);
            }

            if (m_filter.Portlist.Count > 0)
            {
                if (!m_filter.PortExluded)
                {
                    if ((!m_filter.IncludedPort(destport) &&
                         !m_filter.IncludedPort(srcport))
                        )
                    {
                        return(false);
                    }
                }
                else
                {
                    if ((m_filter.IncludedPort(destport) ||
                         m_filter.IncludedPort(srcport))
                        )
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }