Пример #1
0
        public DnsQuestion(NetBinaryReader nbr)
        {
            List<string> labels = new List<string>();
            byte nameLength;

            while ((nameLength = nbr.ReadByte()) != 0)
            {
                string label = string.Empty;

                for (int i = 0; i < nameLength; i++)
                {
                    label += (char)nbr.ReadByte();
                }

                labels.Add(label);
            }

            QueriedDomainName = string.Join(".", labels);
            Type = (QType)nbr.ReadUInt16();

            ushort rawClass = nbr.ReadUInt16();
            if (rawClass > 65279) rawClass = 0;
            else if (rawClass > 4 && rawClass < 252) rawClass = 2;
            else if (rawClass > 255 && rawClass < 65280) rawClass = 2;
            Class = (DnsClass)rawClass;
        }
Пример #2
0
        public IPHeader(byte[] byBuffer, int nReceived)
        {
            NetBinaryReader nbr = new NetBinaryReader(byBuffer, 0, nReceived);

            Version = nbr.ReadNible();
            HeaderLength = nbr.ReadNible();

            Precedence = (Precedence)nbr.ReadCustomAmount(3);
            LowDelay = nbr.ReadBit();
            HighThroughput = nbr.ReadBit();
            HighRelibility = nbr.ReadBit();
            nbr.SkipPadBits();

            TotalLength = nbr.ReadUInt16();
            Identification = nbr.ReadUInt16();

            nbr.ReadBit();
            MayFragment = !nbr.ReadBit();
            LastFragment = !nbr.ReadBit();
            FragmentOffset = (nbr.ReadPadBits() << 3) + nbr.ReadByte();

            TTL = nbr.ReadByte();
            Protocol = (ProtocolType)nbr.ReadByte();
            HeaderChecksum = IPAddress.NetworkToHostOrder(nbr.ReadInt16());

            Source = new IPAddress(nbr.ReadBytes(4));
            Destination = new IPAddress(nbr.ReadBytes(4));
        }
Пример #3
0
        public TcpHeader(byte[] byIpData, int start)
        {
            NetBinaryReader nbr = new NetBinaryReader(byIpData, start);

            SourcePort = nbr.ReadUInt16();
            DestinationPort = nbr.ReadUInt16();

            SequenceNumber = nbr.ReadUInt32();
            AcknowledgmentNumber = nbr.ReadUInt32();

            DataOffset = nbr.ReadNible();
            nbr.SkipPadBits();

            nbr.ReadCustomAmount(2);
            URG = nbr.ReadBit();
            ACK = nbr.ReadBit();
            PSH = nbr.ReadBit();
            RST = nbr.ReadBit();
            SYN = nbr.ReadBit();
            FIN = nbr.ReadBit();

            Window = nbr.ReadUInt16();
            Checksum = nbr.ReadUInt16();
            UrgentPointer = nbr.ReadUInt16();

            //TODO: test
            byte option;
            long optionsStart = nbr.BaseStream.Position;
            Options = new byte[0][];

            while ((option = nbr.ReadByte()) != 0 || nbr.BaseStream.Position > start + DataOffset)    // 0 = End list
            {
                if (option == 1) continue;  // 1 = No Option
                if (option == 2)            // Max Segm size
                {
                    byte length = nbr.ReadByte();

                    byte[] cur = new byte[length];
                    for (byte i = 0; i < length; i++)
                    {
                        cur[i] = nbr.ReadByte();
                    }

                    Array.Resize(ref Options, Options.Length + 1);
                    Options[Options.Length - 1] = cur;
                }
            }

            long dataLength = DataOffset - optionsStart;
            Data = new byte[dataLength];
            for (int i = 0; i < dataLength; i++)
            {
                Data[i] = nbr.ReadByte();
            }
        }
Пример #4
0
        public IcmpHeader(byte[] byIpData, int start, int bytesReceived)
        {
            NetBinaryReader nbr = new NetBinaryReader(byIpData, start);

            byte type = nbr.ReadByte();
            if (type == 2 || type == 7) type = 1;
            else if (type > 20 && type < 30) type = 20;
            else if (type > 41) type = 41;
            Type = (MessageType)type;

            Code = nbr.ReadByte();
            Checksum = nbr.ReadUInt16();

            data = new byte[bytesReceived - start - OCTET_COUNT];
            Array.Copy(byIpData, start + OCTET_COUNT, data, 0, data.Length);
        }