internal static void ARPCache_Update(ARPReply_Ethernet arp_reply) { ensureQueueExists(); //foreach (BufferEntry entry in queue) for (int e = 0; e < queue.Count; e++) { BufferEntry entry = queue[e]; if (entry.Status == BufferEntry.EntryStatus.ARP_SENT) { var xDestIP = entry.Packet.DestinationIP.Hash; var xSenderIP = arp_reply.SenderIP.Hash; if (entry.Packet.DestinationIP.CompareTo(arp_reply.SenderIP) == 0) { entry.Packet.DestinationMAC = arp_reply.SenderMAC; entry.Status = BufferEntry.EntryStatus.JUST_SEND; } } else if (entry.Status == BufferEntry.EntryStatus.ROUTE_ARP_SENT) { if (entry.nextHop.CompareTo(arp_reply.SenderIP) == 0) { entry.Packet.DestinationMAC = arp_reply.SenderMAC; entry.Status = BufferEntry.EntryStatus.JUST_SEND; } } } }
/// <summary> /// Initialize the Network Stack to prepare it for operation. /// </summary> /// <exception cref="ArgumentOutOfRangeException">Thrown on fatal error (contact support).</exception> public static void Init() { AddressMap = new TempDictionary <NetworkDevice>(); // VMT Scanner issue workaround ARPPacket.VMTInclude(); ARPPacket_Ethernet.VMTInclude(); ARPReply_Ethernet.VMTInclude(); ARPRequest_Ethernet.VMTInclude(); ICMPPacket.VMTInclude(); ICMPEchoReply.VMTInclude(); ICMPEchoRequest.VMTInclude(); UDPPacket.VMTInclude(); //TCPPacket.VMTInclude(); }
internal static void ARPHandler(byte[] packetData) { ARPPacket arp_packet = new ARPPacket(packetData); //[Received] " + arp_packet.ToString() if (arp_packet.Operation == 0x01) { if ((arp_packet.HardwareType == 1) && (arp_packet.ProtocolType == 0x0800)) { ARPRequest_Ethernet arp_request = new ARPRequest_Ethernet(packetData); if (arp_request.SenderIP == null) { //SenderIP null in ARPHandler! } arp_request = new ARPRequest_Ethernet(packetData); ARPCache.Update(arp_request.SenderIP, arp_request.SenderMAC); if (NetworkStack.AddressMap.ContainsKey(arp_request.TargetIP.Hash) == true) { //ARP Request Recvd from " + arp_request.SenderIP.ToString() NetworkDevice nic = NetworkStack.AddressMap[arp_request.TargetIP.Hash]; ARPReply_Ethernet reply = new ARPReply_Ethernet(nic.MACAddress, arp_request.TargetIP, arp_request.SenderMAC, arp_request.SenderIP); nic.QueueBytes(reply.RawData); } } } else if (arp_packet.Operation == 0x02) { if ((arp_packet.HardwareType == 1) && (arp_packet.ProtocolType == 0x0800)) { ARPReply_Ethernet arp_reply = new ARPReply_Ethernet(packetData); //Received ARP Reply //arp_reply.ToString() //ARP Reply Recvd from " + arp_reply.SenderIP.ToString() ARPCache.Update(arp_reply.SenderIP, arp_reply.SenderMAC); IPV4.OutgoingBuffer.ARPCache_Update(arp_reply); } } }