コード例 #1
0
        private void I_OnPacketArrival(object sender, CaptureEventArgs e)
        {
            int           len      = 0;
            TCPUDP        protocol = TCPUDP.TCP;
            PacketAddress address  = Tool.GetPacketAddressFromRowPacket(e.Packet, ref len, ref protocol);

            if (address != null && len != 0)
            {
                PacketFlow packetFlow = networkStructure.GetPacketFlow(address);
                packetFlow.protocol = protocol;
                uploadDownloadMap.AddPacket(packetFlow, len);
            }
        }
コード例 #2
0
 /// <summary>
 /// Get the data flow direction of a packet.
 /// </summary>
 /// <param name="address">Addresses of a packet</param>
 /// <returns>Data flow direction</returns>
 public PacketFlow GetPacketFlow(PacketAddress address)
 {
     lock (this)
     {
         if (!cache.TryGetValue(address, out PacketFlow result))
         {
             result = new PacketFlow();
             if (myIPSet.Contains(address.source))
             {
                 if (myIPSet.Contains(address.destination))
                 {
                     result.type = PacketFlow.FlowType.DROP;
                 }
                 else
                 {
                     result.type         = PacketFlow.FlowType.UPLOAD;
                     result.hasIPAndPort = true;
                     result.myIP         = address.source;
                     result.port         = address.sourcePort;
                 }
             }
             else
             {
                 if (myIPSet.Contains(address.destination))
                 {
                     result.type         = PacketFlow.FlowType.DOWNLOAD;
                     result.hasIPAndPort = true;
                     result.myIP         = address.destination;
                     result.port         = address.destinationPort;
                 }
                 else
                 {
                     if (IsAddressInNetwork(address.source))
                     {
                         if (IsAddressInNetwork(address.destination))
                         {
                             result.type = PacketFlow.FlowType.DROP;
                         }
                         else
                         {
                             result.type         = PacketFlow.FlowType.DOWNLOAD;
                             result.hasIPAndPort = false;
                         }
                     }
                     else
                     {
                         if (IsAddressInNetwork(address.destination))
                         {
                             result.type         = PacketFlow.FlowType.UPLOAD;
                             result.hasIPAndPort = false;
                         }
                         else
                         {
                             result.type = PacketFlow.FlowType.DROP;
                         }
                     }
                 }
             }
             cache[address] = result;
         }
         return(result);
     }
 }