Ejemplo n.º 1
0
        unsafe public int GetINTERNETPart(int CurrentPtr)
        {
            byte    b     = 0;
            ushort  us    = 0;
            byte *  ptr   = ( byte * )CurrentPtr;
            ushort *usptr = ( ushort * )CurrentPtr;

            b = *(ptr++);
            PInternet.Version      = (byte)((int)b >> 4);
            PInternet.HeaderLength = (byte)(((int)b & 0x0f) * 4);

            b = *(ptr++);
            PInternet.DifferentiatedServicesField    = b;
            PInternet.DifferentiatedServicesFieldStr = "";
            if ((b & 0x0d) > 0)
            {
                PInternet.DifferentiatedServicesFieldStr += "Differentiated Services Codepoint ( Default : 0x00 ),";
            }
            if ((b & 0x02) > 0)
            {
                PInternet.DifferentiatedServicesFieldStr += "ECN Capable Transport ( ECT ),";
            }
            if ((b & 0x01) > 0)
            {
                PInternet.DifferentiatedServicesFieldStr += "ECN-CE,";
            }

            if (PInternet.DifferentiatedServicesFieldStr != "")
            {
                PInternet.DifferentiatedServicesFieldStr = PInternet.DifferentiatedServicesFieldStr.Substring(0, PInternet.DifferentiatedServicesFieldStr.Length - 1);
            }

            us = AllFunctions.Get2Bytes(ptr, NORMAL); ptr += 2;
            PInternet.Length = us;

            us = AllFunctions.Get2Bytes(ptr, NORMAL); ptr += 2;
            PInternet.Identification = us;

            us = AllFunctions.Get2Bytes(ptr, NORMAL); ptr += 2;
            PInternet.Flags = (byte)((int)us >> 12);
            if ((PInternet.Flags & 0x04) > 0)
            {
                PInternet.FlagsStr = "Dont fragment";
            }
            if ((PInternet.Flags & 0x02) > 0)
            {
                PInternet.FlagsStr = "More fragments";
            }

            PInternet.FragmentOffset = (ushort)((int)us & 0x0f);

            b = *(ptr++);
            PInternet.TimeToLive = b;

            b = *(ptr++);
            PInternet.Protocol    = b;
            PInternet.ProtocolStr = GetProtocolStr((int)b);

            us = AllFunctions.Get2Bytes(ptr, NORMAL); ptr += 2;
            PInternet.HeaderChecksum = us;

            PInternet.SourceStr = "";
            b = *(ptr++);
            PInternet.SourceStr += b.ToString() + ".";
            b = *(ptr++);
            PInternet.SourceStr += b.ToString() + ".";
            b = *(ptr++);
            PInternet.SourceStr += b.ToString() + ".";
            b = *(ptr++);
            PInternet.SourceStr += b.ToString();
            PInternet.Source     = (uint)AllFunctions.IpAddressToInt(PInternet.SourceStr);

            PInternet.DestinationStr = "";
            b = *(ptr++);
            PInternet.DestinationStr += b.ToString() + ".";
            b = *(ptr++);
            PInternet.DestinationStr += b.ToString() + ".";
            b = *(ptr++);
            PInternet.DestinationStr += b.ToString() + ".";
            b = *(ptr++);
            PInternet.DestinationStr += b.ToString();
            PInternet.Destination     = (uint)AllFunctions.IpAddressToInt(PInternet.DestinationStr);

            return(CurrentPtr + PACKET_INTERNET_LENGTH);
        }