Exemplo n.º 1
0
        private static void ARPHandler(byte[] packetData)
        {
            ARP.ARPPacket arp_packet = new ARP.ARPPacket(packetData);
            if (arp_packet.Operation == 0x01)
            {
                if ((arp_packet.HardwareType == 1) && (arp_packet.ProtocolType == 0x0800))
                {
                    ARP.ARPRequest_EthernetIPv4 arp_request = new ARP.ARPRequest_EthernetIPv4(packetData);
                    ARP.ARPCache.Update(arp_request.SenderIP, arp_request.SenderMAC);

                    if (addressMap.ContainsKey(arp_request.TargetIP.To32BitNumber()) == true)
                    {
                        //Console.WriteLine("ARP Request Recvd from " + arp_request.SenderIP.ToString());
                        HW.Network.NetworkDevice nic = addressMap[arp_request.TargetIP.To32BitNumber()];

                        ARP.ARPReply_EthernetIPv4 reply =
                            new ARP.ARPReply_EthernetIPv4(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))
                {
                    ARP.ARPReply_EthernetIPv4 arp_reply = new ARP.ARPReply_EthernetIPv4(packetData);
                    ARP.ARPCache.Update(arp_reply.SenderIP, arp_reply.SenderMAC);

                    //Console.WriteLine("ARP Reply Recvd for IP=" + arp_reply.SenderIP.ToString());
                    TCPIP.IPv4OutgoingBuffer.ARPCache_Update(arp_reply);
                }
            }
        }
Exemplo n.º 2
0
        private static void ARPHandler(byte[] packetData)
        {
            ARP.ARPPacket arp_packet = new ARP.ARPPacket(packetData);
            if (arp_packet.Operation == 0x01)
            {
                if ((arp_packet.HardwareType == 1) && (arp_packet.ProtocolType == 0x0800))
                {
                    ARP.ARPRequest_EthernetIPv4 arp_request = new ARP.ARPRequest_EthernetIPv4(packetData);
                    ARP.ARPCache.Update(arp_request.SenderIP, arp_request.SenderMAC);

                    if (addressMap.ContainsKey(arp_request.TargetIP.To32BitNumber()) == true)
                    {
                        //Console.WriteLine("ARP Request Recvd from " + arp_request.SenderIP.ToString());
                        HW.Network.NetworkDevice nic = addressMap[arp_request.TargetIP.To32BitNumber()];

                        ARP.ARPReply_EthernetIPv4 reply =
                            new ARP.ARPReply_EthernetIPv4(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))
                {
                    ARP.ARPReply_EthernetIPv4 arp_reply = new ARP.ARPReply_EthernetIPv4(packetData);
                    ARP.ARPCache.Update(arp_reply.SenderIP, arp_reply.SenderMAC);

                    //Console.WriteLine("ARP Reply Recvd for IP=" + arp_reply.SenderIP.ToString());
                    TCPIP.IPv4OutgoingBuffer.ARPCache_Update(arp_reply);
                }
            }
        }