예제 #1
0
        internal static void ARPHandler(byte[] packetData)
        {
            ARPPacket arp_packet = new ARPPacket(packetData);

            //Sys.Console.WriteLine("Received ARP Packet");
            //Sys.Console.WriteLine(arp_packet.ToString());
            if (arp_packet.Operation == 0x01)
            {
                if ((arp_packet.HardwareType == 1) && (arp_packet.ProtocolType == 0x0800))
                {
                    IPv4.ARPRequest_Ethernet arp_request = new IPv4.ARPRequest_Ethernet(packetData);
                    if (arp_request.SenderIP == null)
                    {
                        global::System.Console.WriteLine("SenderIP null in ARPHandler!");
                    }
                    arp_request = new IPv4.ARPRequest_Ethernet(packetData);

                    ARPCache.Update(arp_request.SenderIP, arp_request.SenderMAC);

                    if (NetworkStack.AddressMap.ContainsKey(arp_request.TargetIP.Hash) == true)
                    {
                        //Sys.Console.WriteLine("ARP Request Recvd from " + arp_request.SenderIP.ToString());
                        NetworkDevice nic = NetworkStack.AddressMap[arp_request.TargetIP.Hash];

                        IPv4.ARPReply_Ethernet reply =
                            new IPv4.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))
                {
                    IPv4.ARPReply_Ethernet arp_reply = new IPv4.ARPReply_Ethernet(packetData);
                    //Sys.Console.WriteLine("Received ARP Reply");
                    //Sys.Console.WriteLine(arp_reply.ToString());
                    //Sys.Console.WriteLine("ARP Reply Recvd from " + arp_reply.SenderIP.ToString());
                    ARPCache.Update(arp_reply.SenderIP, arp_reply.SenderMAC);

                    IPv4.OutgoingBuffer.ARPCache_Update(arp_reply);
                }
            }
        }
예제 #2
0
파일: ARPPacket.cs 프로젝트: Orvid/Cosmos
        internal static void ARPHandler(byte[] packetData)
        {
            ARPPacket arp_packet = new ARPPacket(packetData);
            //Sys.Console.WriteLine("Received ARP Packet");
            //Sys.Console.WriteLine(arp_packet.ToString());
            if (arp_packet.Operation == 0x01)
            {
                if ((arp_packet.HardwareType == 1) && (arp_packet.ProtocolType == 0x0800))
                {
                    IPv4.ARPRequest_Ethernet arp_request = new IPv4.ARPRequest_Ethernet(packetData);
                    if (arp_request.SenderIP == null)
                    {
                        global::System.Console.WriteLine("SenderIP null in ARPHandler!");
                    }
                    arp_request = new IPv4.ARPRequest_Ethernet(packetData);
                    
                    ARPCache.Update(arp_request.SenderIP, arp_request.SenderMAC);

                    if (NetworkStack.AddressMap.ContainsKey(arp_request.TargetIP.Hash) == true)
                    {
                        //Sys.Console.WriteLine("ARP Request Recvd from " + arp_request.SenderIP.ToString());
                        NetworkDevice nic = NetworkStack.AddressMap[arp_request.TargetIP.Hash];

                        IPv4.ARPReply_Ethernet reply =
                            new IPv4.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))
                {
                    IPv4.ARPReply_Ethernet arp_reply = new IPv4.ARPReply_Ethernet(packetData);
                    //Sys.Console.WriteLine("Received ARP Reply");
                    //Sys.Console.WriteLine(arp_reply.ToString());
                    //Sys.Console.WriteLine("ARP Reply Recvd from " + arp_reply.SenderIP.ToString());
                    ARPCache.Update(arp_reply.SenderIP, arp_reply.SenderMAC);

                    IPv4.OutgoingBuffer.ARPCache_Update(arp_reply);
                }
            }
        }