Example #1
0
        public TcpPacket HandleTcpPacket()
        {
            TcpPacket packet      = new TcpPacket();
            int       source_port = HeaderParser.ToInt(this.Data, 0, 16);
            int       dest_port   = HeaderParser.ToInt(this.Data, 16, 16);
            int       offset      = HeaderParser.ToInt(this.Data, 96, 4) * 4;

            packet.Source          = new IPEndPoint(this.Source, source_port);
            packet.Destination     = new IPEndPoint(this.Destination, dest_port);
            packet.Sequence        = HeaderParser.ToUInt(this.Data, 32, 32);
            packet.Acknowledgement = HeaderParser.ToUInt(this.Data, 64, 32);
            packet.DataOffset      = offset;
            packet.Urgent          = HeaderParser.ToByte(this.Data, 106, 1) != 0;
            packet.Ack             = HeaderParser.ToByte(this.Data, 107, 1) != 0;
            packet.Push            = HeaderParser.ToByte(this.Data, 108, 1) != 0;
            packet.Reset           = HeaderParser.ToByte(this.Data, 109, 1) != 0;
            packet.Syn             = HeaderParser.ToByte(this.Data, 110, 1) != 0;
            packet.Fin             = HeaderParser.ToByte(this.Data, 111, 1) != 0;


            packet.WindowSize    = HeaderParser.ToInt(this.Data, 112, 16);
            packet.Checksum      = HeaderParser.ToInt(this.Data, 128, 16);
            packet.UrgentPointer = HeaderParser.ToInt(this.Data, 144, 16);

            if (offset > 20)
            {
                packet.SetData(this.Data, 20, offset - 20);
            }

            packet.SetData(this.Data, offset, this.Data.Length - offset);
            return(packet);
        }
Example #2
0
 public bool SetFields(Byte[] buffer)
 {
     if (buffer.Length >= this.HeaderLength_)
     {
         int [] x = new int[2];
         for (int i = 0; i < Keys_.Count; i++)
         {
             x = (int[])FieldLengths_[Keys_[i]];
             if (x[1] <= 8)
             {
                 Fields_.Add(Keys_[i], HeaderParser.ToByte(buffer, x[0], x[1]));
             }
             else if (x[1] <= 16)
             {
                 Fields_.Add(Keys_[i], HeaderParser.ToInt(buffer, x[0], x[1]));
             }
             else if (x[1] <= 32)
             {
                 Fields_.Add(Keys_[i], HeaderParser.ToUInt(buffer, x[0], x[1]));
             }
         }
         this.SetData(buffer, this.HeaderLength_, buffer.Length - this.HeaderLength_);
         Length_ = buffer.Length;
         return(true);
     }
     return(false);
 }
Example #3
0
        public IcmpPacket HandleIcmpPacket()
        {
            IcmpPacket packet = new IcmpPacket();

            packet.Source      = new IPEndPoint(this.Source, 0);
            packet.Destination = new IPEndPoint(this.Destination, 0);
            packet.Type        = HeaderParser.ToByte(this.Data, 0, 8);
            packet.Code        = HeaderParser.ToByte(this.Data, 8, 8);
            packet.Checksum    = HeaderParser.ToUShort(this.Data, 16, 16);
            packet.SetData(this.Data, 4, this.Data.Length - 4);
            return(packet);
        }