Exemple #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);
                }
            }
        }
Exemple #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);
                }
            }
        }
Exemple #3
0
        internal static void Send()
        {
            ensureQueueExists();
            if (queue.Count < 1)
            {
                return;
            }

            //foreach (BufferEntry entry in queue)
            for (int e = 0; e < queue.Count; e++)
            {
                BufferEntry entry = queue[e];
                if (entry.Status == BufferEntry.EntryStatus.ADDED)
                {
                    if (TCPIPStack.IsLocalAddress(entry.Packet.DestinationIP) == false)
                    {
                        entry.nextHop = TCPIPStack.FindRoute(entry.Packet.DestinationIP);
                        if (entry.nextHop == null)
                        {
                            entry.Status = BufferEntry.EntryStatus.DONE;
                            continue;
                        }

                        if (ARP.ARPCache.Contains(entry.nextHop) == true)
                        {
                            entry.Packet.DestinationMAC = ARP.ARPCache.Resolve(entry.nextHop);

                            entry.NIC.QueueBytes(entry.Packet.RawData);

                            entry.Status = BufferEntry.EntryStatus.DONE;
                        }
                        else
                        {
                            ARP.ARPRequest_EthernetIPv4 arp_request = new ARP.ARPRequest_EthernetIPv4(entry.NIC.MACAddress, entry.Packet.SourceIP,
                                HW.Network.MACAddress.Broadcast, entry.nextHop);

                            entry.NIC.QueueBytes(arp_request.RawData);

                            entry.Status = BufferEntry.EntryStatus.ROUTE_ARP_SENT;
                        }
                        continue;
                    }

                    if (ARP.ARPCache.Contains(entry.Packet.DestinationIP) == true)
                    {
                        entry.Packet.DestinationMAC = ARP.ARPCache.Resolve(entry.Packet.DestinationIP);

                        entry.NIC.QueueBytes(entry.Packet.RawData);

                        entry.Status = BufferEntry.EntryStatus.DONE;
                    }
                    else
                    {
                        ARP.ARPRequest_EthernetIPv4 arp_request = new ARP.ARPRequest_EthernetIPv4(entry.NIC.MACAddress, entry.Packet.SourceIP,
                            HW.Network.MACAddress.Broadcast, entry.Packet.DestinationIP);

                        entry.NIC.QueueBytes(arp_request.RawData);

                        entry.Status = BufferEntry.EntryStatus.ARP_SENT;
                    }
                }
                else if (entry.Status == BufferEntry.EntryStatus.JUST_SEND)
                {
                    entry.NIC.QueueBytes(entry.Packet.RawData);

                    entry.Status = BufferEntry.EntryStatus.DONE;
                }
            }

            int i = 0;
            while (i < queue.Count)
            {
                if (queue[i].Status == BufferEntry.EntryStatus.DONE)
                {
                    queue.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }
        }
        internal static void Send()
        {
            ensureQueueExists();
            if (queue.Count < 1)
            {
                return;
            }

            //foreach (BufferEntry entry in queue)
            for (int e = 0; e < queue.Count; e++)
            {
                BufferEntry entry = queue[e];
                if (entry.Status == BufferEntry.EntryStatus.ADDED)
                {
                    if (TCPIPStack.IsLocalAddress(entry.Packet.DestinationIP) == false)
                    {
                        entry.nextHop = TCPIPStack.FindRoute(entry.Packet.DestinationIP);
                        if (entry.nextHop == null)
                        {
                            entry.Status = BufferEntry.EntryStatus.DONE;
                            continue;
                        }

                        if (ARP.ARPCache.Contains(entry.nextHop) == true)
                        {
                            entry.Packet.DestinationMAC = ARP.ARPCache.Resolve(entry.nextHop);

                            entry.NIC.QueueBytes(entry.Packet.RawData);

                            entry.Status = BufferEntry.EntryStatus.DONE;
                        }
                        else
                        {
                            ARP.ARPRequest_EthernetIPv4 arp_request = new ARP.ARPRequest_EthernetIPv4(entry.NIC.MACAddress, entry.Packet.SourceIP,
                                                                                                      HW.Network.MACAddress.Broadcast, entry.nextHop);

                            entry.NIC.QueueBytes(arp_request.RawData);

                            entry.Status = BufferEntry.EntryStatus.ROUTE_ARP_SENT;
                        }
                        continue;
                    }

                    if (ARP.ARPCache.Contains(entry.Packet.DestinationIP) == true)
                    {
                        entry.Packet.DestinationMAC = ARP.ARPCache.Resolve(entry.Packet.DestinationIP);

                        entry.NIC.QueueBytes(entry.Packet.RawData);

                        entry.Status = BufferEntry.EntryStatus.DONE;
                    }
                    else
                    {
                        ARP.ARPRequest_EthernetIPv4 arp_request = new ARP.ARPRequest_EthernetIPv4(entry.NIC.MACAddress, entry.Packet.SourceIP,
                                                                                                  HW.Network.MACAddress.Broadcast, entry.Packet.DestinationIP);

                        entry.NIC.QueueBytes(arp_request.RawData);

                        entry.Status = BufferEntry.EntryStatus.ARP_SENT;
                    }
                }
                else if (entry.Status == BufferEntry.EntryStatus.JUST_SEND)
                {
                    entry.NIC.QueueBytes(entry.Packet.RawData);

                    entry.Status = BufferEntry.EntryStatus.DONE;
                }
            }

            int i = 0;

            while (i < queue.Count)
            {
                if (queue[i].Status == BufferEntry.EntryStatus.DONE)
                {
                    queue.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }
        }