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); }
public NewBytesEventArgs(IP.SocketID socketID) { SocketID = socketID; }