Exemple #1
0
        static void dev_OnPacketArrival(object sender, CaptureEventArgs e)
        {
            Packet packet = IpPacket.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);

            IPv4Packet pv4 = packet.PayloadPacket as IPv4Packet;
            IPv6Packet pv6 = packet.PayloadPacket as IPv6Packet;

            if (pv4 != null)
            {
                total += pv4.TotalLength;
                String src = pv4.SourceAddress.ToString();
                String dst = pv4.DestinationAddress.ToString();

                Console.Out.WriteLine(src + " --> " + dst + "\tlen:" + pv4.TotalLength);
            }

            if (pv6 != null)
            {
                total += pv6.TotalLength;
                String src = pv6.SourceAddress.ToString();
                String dst = pv6.DestinationAddress.ToString();

                Console.Out.WriteLine(src + " --> " + dst + "\tlen:" + pv6.TotalLength);
            }

            //Console.Out.WriteLine(total);
        }
Exemple #2
0
 private void capDev_OnPacketArrival(object sender, CaptureEventArgs e)
 {
     lock (packetQueue)
     {
         try
         {
             packetQueue.Enqueue(IpPacket.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data));
             if (packetQueue.Count == 1)
             {
                 System.Threading.Monitor.Pulse(packetQueue);
             }
         }
         catch (Exception ex)
         {
             AppendLog("Error: capDev_OnPacketArrival" + ex.Message);
         }
     }
 }