예제 #1
0
        //dirt simple is the name of the game
        public static void ProcessIncomingPacket(Bytes packet, IAdapter adapter)
        {
            IpHeader ipHeader = new IpHeader(packet, EthernetHeader.Size);

            //since we apparently don't support fragments yet.
            if (ipHeader.MoreFragmentsFollowing() == true)
            {
                DebugPrint("ACK! ip fragmentation!\n");
                return;
            }
            //            DebugStub.Assert(ipHeader.MoreFragmentsFollowing() == false);
            //VTable.Assert(ipHeader.MoreFragmentsFollowing() == false);

            if (ipHeader.IsChecksumValid() == false)
            {
                DebugPrint("ProcessIncomingPacket: bad checksum...dropping packets\n");
                //delete packet;
                return;
            }
            //make sure the address is 'local'
            if (hostConfiguration == null)
            {
                DebugPrint("ACK hostConfiguration is NULL\n");
                return;
            }

            if ((hostConfiguration.IsLocalAddress(ipHeader.destAddress) == false) &&
                (ipHeader.destAddress != IPv4.Broadcast))
            {
                //                DebugPrint("ProcessIncomingPacket: wrong address ...dropping packets\n");
                //                DebugPrint("Dest address {0}\n", ipHeader.destAddress);
                //delete packet;
                return;
            }

            try {
                //figure out to which protocol the packet belongs
                switch (ipHeader.protocol)
                {
                case IpHeader.TCP:
                    DebugPrint("ProcessIncomingPacket: Got TCP packet\n");
                    //TCP.ProcessIncomingPacket(packet, ipHeader);
                    break;

                case IpHeader.UDP:
                    //DebugPrint("ProcessIncomingPacket: Got UDP packet\n");
                    UDP.ProcessIncomingPacket(packet, ipHeader);
                    break;

                case IpHeader.ICMP:
                    DebugPrint("ProcessIncomingPacket: Got ICMP packet\n");
                    //delete packet;
                    break;

                default:
                    DebugPrint("Got unexpected packet!!\n");
                    //delete packet;
                    DebugStub.Break();
                    break;
                }
            }
            catch (Exception e) {
                DebugStub.Print("Caught exception {0}\n", DebugStub.ArgList(e));
                DebugStub.Break();
            }
        }