Exemplo n.º 1
0
        /// <summary>
        /// Init TCPPacket fields.
        /// </summary>
        /// <exception cref="sys.ArgumentException">Thrown if RawData is invalid or null.</exception>
        protected override void InitFields()
        {
            base.InitFields();
            SourcePort      = (ushort)((RawData[DataOffset] << 8) | RawData[DataOffset + 1]);
            DestinationPort = (ushort)((RawData[DataOffset + 2] << 8) | RawData[DataOffset + 3]);
            SequenceNumber  = (uint)((RawData[DataOffset + 4] << 24) | (RawData[DataOffset + 5] << 16) | (RawData[DataOffset + 6] << 8) | RawData[DataOffset + 7]);
            AckNumber       = (uint)((RawData[DataOffset + 8] << 24) | (RawData[DataOffset + 9] << 16) | (RawData[DataOffset + 10] << 8) | RawData[DataOffset + 11]);
            TCPHeaderLength = (byte)((RawData[DataOffset + 12] >> 4) * 4);
            TCPFlags        = RawData[DataOffset + 13];
            WindowSize      = (ushort)((RawData[DataOffset + 14] << 8) | RawData[DataOffset + 15]);
            Checksum        = (ushort)((RawData[DataOffset + 16] << 8) | RawData[DataOffset + 17]);
            UrgentPointer   = (ushort)((RawData[DataOffset + 18] << 8) | RawData[DataOffset + 19]);

            SYN = (RawData[47] & (byte)Flags.SYN) != 0;
            ACK = (RawData[47] & (byte)Flags.ACK) != 0;
            FIN = (RawData[47] & (byte)Flags.FIN) != 0;
            PSH = (RawData[47] & (byte)Flags.PSH) != 0;
            RST = (RawData[47] & (byte)Flags.RST) != 0;
            URG = (RawData[47] & (byte)Flags.URG) != 0;

            if (TCPHeaderLength > 20) //options
            {
                Options = new List <TCPOption>();

                for (int i = 0; i < TCP_DataLength; i++)
                {
                    var option = new TCPOption();
                    option.Kind = RawData[DataOffset + 20 + i];

                    if (option.Kind != 1) //NOP
                    {
                        option.Length = RawData[DataOffset + 20 + i + 1];

                        if (option.Length != 2)
                        {
                            option.Data = new byte[option.Length - 2];
                            for (int j = 0; j < option.Length - 2; j++)
                            {
                                option.Data[j] = RawData[DataOffset + 20 + i + 2 + j];
                            }
                        }

                        Options.Add(option);

                        i += option.Length - 1;
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Add Option to TCP Packet.
 /// </summary>
 /// <param name="option">TCP Option.</param>
 /// <exception cref="ArgumentException">Thrown if RawData is invalid or null.</exception>
 internal void AddOption(TCPOption option)
 {
     throw new NotImplementedException();
 }