示例#1
0
            public void CheckPacket(Packet packet, MacAddress mac)
            {
                IP.SocketID key = new IP.SocketID();
                if (packet.Ethernet.EtherType == EthernetType.IpV4)
                {
                    // egress key
                    if (packet.Ethernet.Source == mac)
                    {
                        key.LocalEP  = new IPEndPoint(IPAddress.Parse(packet.Ethernet.IpV4.Source.ToString()), packet.Ethernet.IpV4.Udp.SourcePort);
                        key.RemoteEP = new IPEndPoint(IPAddress.Parse(packet.Ethernet.IpV4.Destination.ToString()), packet.Ethernet.IpV4.Udp.DestinationPort);
                    }
                    // ingress key
                    else //if (packet.Ethernet.Destination == mac)
                    {
                        key.LocalEP  = new IPEndPoint(IPAddress.Parse(packet.Ethernet.IpV4.Destination.ToString()), packet.Ethernet.IpV4.Udp.DestinationPort);
                        key.RemoteEP = new IPEndPoint(IPAddress.Parse(packet.Ethernet.IpV4.Source.ToString()), packet.Ethernet.IpV4.Udp.SourcePort);
                    }
                    key.Protocol = (IP.ProtocolFamily)packet.Ethernet.IpV4.Protocol;
                }
                else //if (packet.Ethernet.EtherType == EthernetType.IpV6)
                {
                    // egress key
                    if (packet.Ethernet.Source == mac)
                    {
                        key.LocalEP  = new IPEndPoint(IPAddress.Parse(packet.Ethernet.IpV6.Source.ToString()), packet.Ethernet.IpV6.Udp.SourcePort);
                        key.RemoteEP = new IPEndPoint(IPAddress.Parse(packet.Ethernet.IpV6.CurrentDestination.ToString()), packet.Ethernet.IpV6.Udp.DestinationPort);
                    }
                    // ingress key
                    else //if (packet.Ethernet.Destination == mac)
                    {
                        key.LocalEP  = new IPEndPoint(IPAddress.Parse(packet.Ethernet.IpV6.CurrentDestination.ToString()), packet.Ethernet.IpV6.Udp.DestinationPort);
                        key.RemoteEP = new IPEndPoint(IPAddress.Parse(packet.Ethernet.IpV6.Source.ToString()), packet.Ethernet.IpV6.Udp.SourcePort);
                    }
                    key.Protocol = (IP.ProtocolFamily)packet.Ethernet.IpV6.NextHeader;
                }
                // egress update
                if (packet.Ethernet.Source == mac)
                {
                    byteTable.AddOrUpdate(key, new Bytes(0, packet.Ethernet.PayloadLength), (k, v) => v.Update(0, packet.Ethernet.PayloadLength));
                }
                // ingress update
                else //if (packet.Ethernet.Destination == mac)
                {
                    byteTable.AddOrUpdate(key, new Bytes(packet.Ethernet.PayloadLength, 0), (k, v) => v.Update(packet.Ethernet.PayloadLength, 0));
                }

                if (NewBytes != null)
                {
                    NewBytes(null, new NewBytesEventArgs(key));
                }
                //if (Global.Config.Gadget.Debug)
                //    Global.WriteLog("New bytes: " +
                //        key.LocalEP.Address.ToString() + ":" + key.LocalEP.Port + (packet.Ethernet.Source == mac ? " -> " : " <- ") +
                //        key.RemoteEP.Address.ToString() + ":" + key.RemoteEP.Port + " " + key.Protocol);
            }
示例#2
0
 public Bytes GetBytes(IP.SocketID socketID)
 {
     if (socketID.Protocol == IP.ProtocolFamily.TCP)
     {
         return(byteTable.GetOrAdd(socketID, new Bytes(0, 0)));
     }
     else //if (socketID.Protocol == IP.ProtocolFamily.UDP)
     {
         if (socketID.LocalEP.Address.GetAddressBytes().Max() > 0)
         {
             Bytes result = byteTable.FirstOrDefault((i) =>
                                                     i.Key.LocalEP.Address.Equals(socketID.LocalEP.Address) &&
                                                     i.Key.LocalEP.Port == socketID.LocalEP.Port).Value;
             if (result == null)
             {
                 return(new Bytes(0, 0));
             }
             else
             {
                 return(result);
             }
         }
         else
         {
             Bytes result = byteTable.FirstOrDefault((i) =>
                                                     i.Key.LocalEP.AddressFamily == socketID.LocalEP.AddressFamily &&
                                                     i.Key.LocalEP.Port == socketID.LocalEP.Port).Value;
             if (result == null)
             {
                 return(new Bytes(0, 0));
             }
             else
             {
                 return(result);
             }
         }
     }
 }
示例#3
0
 public NewBytesEventArgs(IP.SocketID socketID)
 {
     SocketID = socketID;
 }