private void SendARPRequest(IPAddress ipaDestination, IPAddress ipaSource)
        {
            eExNetworkLibrary.ARP.ARPFrame arpRequest = new eExNetworkLibrary.ARP.ARPFrame();
            arpRequest.SourceIP            = ipaSource;
            arpRequest.SourceMAC           = this.PrimaryMACAddress;
            arpRequest.DestinationMAC      = MACAddress.Empty;
            arpRequest.HardwareAddressType = HardwareAddressType.Ethernet;
            arpRequest.DestinationIP       = ipaDestination;

            if (ipaSource.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                arpRequest.ProtocolAddressType = EtherType.IPv4;
            }
            else if (ipaSource.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
            {
                arpRequest.ProtocolAddressType = EtherType.IPv6;
            }

            EthernetFrame ethFrame = new EthernetFrame();

            ethFrame.Source            = this.PrimaryMACAddress;
            ethFrame.Destination       = new MACAddress(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
            ethFrame.EncapsulatedFrame = arpRequest;
            ethFrame.EtherType         = eExNetworkLibrary.EtherType.ARP;

            TrafficDescriptionFrame tdf = new TrafficDescriptionFrame(null, DateTime.Now);

            tdf.EncapsulatedFrame = ethFrame;

            this.Send(ethFrame);
        }
        private void AnalyzeICMP(TrafficDescriptionFrame tdf)
        {
            IPFrame ipFrame = GetIPv6Frame(tdf);
            NeighborAdvertisment icmpNeighborAdvertisment = (NeighborAdvertisment)GetFrameByType(tdf, NeighborAdvertisment.DefaultFrameType);
            NeighborSolicitation icmpNeighborSolicitation = (NeighborSolicitation)GetFrameByType(tdf, NeighborSolicitation.DefaultFrameType);

            if (ipFrame != null && icmpNeighborAdvertisment != null && icmpNeighborAdvertisment.EncapsulatedFrame != null)
            {
                NeighborDiscoveryOption ndOption = (NeighborDiscoveryOption)GetFrameByType(icmpNeighborAdvertisment, NeighborDiscoveryOption.DefaultFrameType);
                if (ndOption.OptionData != null && ndOption.OptionType == NeighborDiscoveryOptionType.TargetLinkLayerAddress)
                {
                    MACAddress macTarget = new MACAddress(ndOption.OptionData);
                    if (!UsesSpoofedAddress(macTarget))
                    {
                        if (!(arpHostTable.Contains(icmpNeighborAdvertisment.TargetAddress) && !icmpNeighborAdvertisment.OverrideFlag))
                        {
                            UpdateAddressTable(macTarget, icmpNeighborAdvertisment.TargetAddress);
                        }
                    }
                }
            }
            else if (ipFrame != null && icmpNeighborSolicitation != null && icmpNeighborSolicitation.EncapsulatedFrame != null)
            {
                NeighborDiscoveryOption ndOption = (NeighborDiscoveryOption)GetFrameByType(icmpNeighborSolicitation, NeighborDiscoveryOption.DefaultFrameType);
                if (ndOption.OptionData != null && ndOption.OptionType == NeighborDiscoveryOptionType.SourceLinkLayerAddress)
                {
                    MACAddress macTarget = new MACAddress(ndOption.OptionData);
                    if (!UsesSpoofedAddress(macTarget))
                    {
                        UpdateAddressTable(macTarget, ipFrame.SourceAddress);
                    }
                }
            }
        }
        void ProcessReceivedData(byte[] bBacketData, WinPcapCaptureHeader wpcHeader)
        {
            EthernetFrame fFrame = new EthernetFrame(bBacketData);

            if (!(bExcludeLocalHostTraffic && IsLocalHostTraffic(fFrame)) && (bPromiscousMode || IsAddressedForThisInterface(fFrame)))
            {
                TrafficDescriptionFrame tdf = new TrafficDescriptionFrame(this, wpcHeader.Timestamp);
                tdf.EncapsulatedFrame = fFrame;

                AnalyzeARP(tdf);
                AnalyzeICMP(tdf);

                InvokeFrameForwarded();
                InvokePacketCaptured(tdf);

                if (OutputHandler != null)
                {
                    NotifyNext(tdf);
                }
                if (AutoAnswerARPRequests)
                {
                    HandleARP(fFrame);
                    HandleICMP(fFrame);
                }
            }
        }
        /// <summary>
        /// Clones this frame.
        /// </summary>
        /// <returns>An identic clone of this frame</returns>
        public override Frame Clone()
        {
            Frame f = new TrafficDescriptionFrame(iSourceInterface, new DateTime(dtCaptureTime.Ticks));

            if (this.EncapsulatedFrame != null)
            {
                f.EncapsulatedFrame = this.EncapsulatedFrame.Clone();
            }
            return(f);
        }
        private void MainWorkingLoop()
        {
            byte[] bFrameBytes = null;
            int    iCount      = 0;

            try
            {
                while (bRun)
                {
                    lock (qFrameQueue)
                    {
                        iCount = qFrameQueue.Count;
                    }

                    while (iCount > 0)
                    {
                        try
                        {
                            lock (qFrameQueue)
                            {
                                bFrameBytes = qFrameQueue.Dequeue();
                            }
                            if (bFrameBytes != null)
                            {
                                lock (oInterfaceStartStopLock)
                                {
                                    wpcDevice.SendPacket(bFrameBytes);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            TrafficDescriptionFrame tdf = new TrafficDescriptionFrame(this, DateTime.Now);
                            tdf.EncapsulatedFrame = new RawDataFrame(bFrameBytes);
                            PushDroppedFrame(tdf);
                            InvokeExceptionThrown(ex);
                        }

                        lock (qFrameQueue)
                        {
                            iCount = qFrameQueue.Count;
                        }
                    }
                    areWorkToDo.WaitOne();
                }
            }
            finally
            {
                lock (qFrameQueue)
                {
                    qFrameQueue.Clear();
                }
            }
        }