Beispiel #1
0
        /// <summary>
        /// IPv4 handler.
        /// </summary>
        /// <param name="packetData">Packet data.</param>
        /// <exception cref="sys.ArgumentOutOfRangeException">Thrown on fatal error (contact support).</exception>
        /// <exception cref="sys.IO.IOException">Thrown on IO error.</exception>
        /// <exception cref="sys.ArgumentException">Thrown on fatal error (contact support).</exception>
        /// <exception cref="sys.OverflowException">Thrown if packetData array length is greater than Int32.MaxValue.</exception>
        internal static void IPv4Handler(byte[] packetData)
        {
            var ip_packet = new IPPacket(packetData);

            if (ip_packet.SourceIP == null)
            {
                Global.mDebugger.Send("SourceIP null in IPv4Handler!");
            }
            ARPCache.Update(ip_packet.SourceIP, ip_packet.SourceMAC);

            if ((NetworkStack.AddressMap.ContainsKey(ip_packet.DestinationIP.Hash) == true) ||
                (ip_packet.DestinationIP.address[3] == 255))
            {
                switch (ip_packet.Protocol)
                {
                case 1:
                    ICMPPacket.ICMPHandler(packetData);
                    break;

                case 6:
                    TCPPacket.TCPHandler(packetData);
                    break;

                case 17:
                    UDPPacket.UDPHandler(packetData);
                    break;
                }
            }
            else if (NetworkStack.MACMap.ContainsKey(ip_packet.DestinationMAC.Hash))
            {
                DHCPPacket.DHCPHandler(packetData);
            }
        }
Beispiel #2
0
        internal static void IPv4Handler(byte[] packetData)
        {
            IPPacket ip_packet = new IPPacket(packetData);

            //[Received] " + ip_packet.ToString()
            if (ip_packet.SourceIP == null)
            {
                //SourceIP null in IPv4Handler!
            }
            ARPCache.Update(ip_packet.SourceIP, ip_packet.SourceMAC);

            if ((NetworkStack.AddressMap.ContainsKey(ip_packet.DestinationIP.Hash) == true) ||
                (ip_packet.DestinationIP.address[3] == 255))
            {
                switch (ip_packet.Protocol)
                {
                case 1:
                    ICMPPacket.ICMPHandler(packetData);
                    break;

                case 6:
                    TCPPacket.TCPHandler(packetData);
                    break;

                case 17:
                    UDPPacket.UDPHandler(packetData);
                    break;
                }
            }
            else if (NetworkStack.MACMap.ContainsKey(ip_packet.DestinationMAC.Hash))
            {
                DHCP.DHCPPacket.DHCPHandler(packetData);
            }
        }
Beispiel #3
0
        internal static void IPv4Handler(byte[] packetData)
        {
            IPPacket ip_packet = new IPPacket(packetData);

            //Sys.Console.WriteLine("Received IP Packet");
            //Sys.Console.WriteLine(ip_packet.ToString());
            ARPCache.Update(ip_packet.SourceIP, ip_packet.SourceMAC);

            if ((NetworkStack.AddressMap.ContainsKey(ip_packet.DestinationIP.Hash) == true) ||
                (ip_packet.DestinationIP.address[3] == 255))
            {
                switch (ip_packet.Protocol)
                {
                case 1:
                    ICMPPacket.ICMPHandler(packetData);
                    break;

                //case 6:
                //    IPv4_TCPHandler(packetData);
                //    break;
                case 17:
                    UDPPacket.UDPHandler(packetData);
                    break;
                }
            }
        }
Beispiel #4
0
        internal static void Send()
        {
            bool wasenabled = false;

            if (Uszka.Kernel.debugger.enabled)
            {
                Uszka.Kernel.debugger.enabled = false;
                wasenabled = true;
            }
            ensureQueueExists();
            int _deltaT = 0;
            int second  = 0;

            while (!(queue.Count < 1))
            {
                if (_deltaT != Cosmos.HAL.RTC.Second)
                {
                    second++;
                    _deltaT = Cosmos.HAL.RTC.Second;
                }

                if (second >= 4)
                {
                    debugger.Send("No response in 4 secondes...");
                    break;
                }

                //foreach (BufferEntry entry in queue)
                for (int e = 0; e < queue.Count; e++)
                {
                    BufferEntry entry = queue[e];
                    if (entry.Status == BufferEntry.EntryStatus.ADDED)
                    {
                        //Need to figure how this is working
                        if (Config.IsLocalAddress(entry.Packet.DestinationIP) == false)
                        {
                            entry.nextHop = Config.FindRoute(entry.Packet.DestinationIP);
                            if (entry.nextHop == null)
                            {
                                entry.Status = BufferEntry.EntryStatus.DONE;
                                continue;
                            }

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

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

                                entry.Status = BufferEntry.EntryStatus.DONE;
                            }
                            else
                            {
                                ARPRequest_Ethernet arp_request = new ARPRequest_Ethernet(entry.NIC.MACAddress, entry.Packet.SourceIP,
                                                                                          MACAddress.Broadcast, entry.nextHop, MACAddress.None);

                                entry.NIC.QueueBytes(arp_request.RawData);

                                entry.Status = BufferEntry.EntryStatus.ROUTE_ARP_SENT;
                            }
                            continue;
                        }
                        if (ARPCache.Contains(entry.Packet.DestinationIP) == true)
                        {
                            entry.Packet.DestinationMAC = ARPCache.Resolve(entry.Packet.DestinationIP);

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

                            entry.Status = BufferEntry.EntryStatus.DONE;
                        }
                        else
                        {
                            ARPRequest_Ethernet arp_request = new ARPRequest_Ethernet(entry.NIC.MACAddress, entry.Packet.SourceIP,
                                                                                      MACAddress.Broadcast, entry.Packet.DestinationIP, MACAddress.None);

                            entry.NIC.QueueBytes(arp_request.RawData);

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

                        entry.Status = BufferEntry.EntryStatus.DONE;
                    }
                    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++;
                    }
                }
            }
            if (wasenabled)
            {
                Uszka.Kernel.debugger.enabled = true;
            }
        }
Beispiel #5
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 (Config.IsLocalAddress(entry.Packet.DestinationIP) == false)
                    {
                        entry.nextHop = Config.FindRoute(entry.Packet.DestinationIP);
                        if (entry.nextHop == null)
                        {
                            entry.Status = BufferEntry.EntryStatus.DONE;
                            continue;
                        }

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

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

                            entry.Status = BufferEntry.EntryStatus.DONE;
                        }
                        else
                        {
                            ARPRequest_Ethernet arp_request = new ARPRequest_Ethernet(entry.NIC.MACAddress, entry.Packet.SourceIP,
                                                                                      MACAddress.Broadcast, entry.nextHop, MACAddress.None);

                            entry.NIC.QueueBytes(arp_request.RawData);

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

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

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

                        entry.Status = BufferEntry.EntryStatus.DONE;
                    }
                    else
                    {
                        ARPRequest_Ethernet arp_request = new ARPRequest_Ethernet(entry.NIC.MACAddress, entry.Packet.SourceIP,
                                                                                  MACAddress.Broadcast, entry.Packet.DestinationIP, MACAddress.None);

                        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++;
                }
            }
            mDebugger.SendInternal($"Number of packages in queue: {i}");
        }