コード例 #1
0
ファイル: IpHeader.cs プロジェクト: Arzana/Sniffles
        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));
        }
コード例 #2
0
ファイル: TcpHeader.cs プロジェクト: Arzana/Sniffles
        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();
            }
        }
コード例 #3
0
ファイル: DnsHeader.cs プロジェクト: Arzana/Sniffles
        public DnsHeader(byte[] byIpData, int start, int bytesReceived)
        {
            NetBinaryReader nbr = new NetBinaryReader(byIpData, start);

            Indentifier = nbr.ReadUInt16();

            QueryOrResponseFlag = nbr.ReadBit();
            OperationCode = (OpCode)nbr.ReadNible();
            AuthoritativeAnswer = nbr.ReadBit();
            Turncation = nbr.ReadBit();
            RecursionDesired = nbr.ReadBit();

            RecursionAvailable = nbr.ReadBit();
            nbr.ReadCustomAmount(3);
            ResponseCode = (RCode)nbr.ReadNible();

            QuestionCount = nbr.ReadUInt16();
            AnswerCount = nbr.ReadUInt16();
            AuthorityCount = nbr.ReadUInt16();
            AdditionalCount = nbr.ReadUInt16();

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