예제 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bas">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        public IPv4Packet(ByteArraySegment bas)
        {
            log.Debug("");

            header = new ByteArraySegment(bas);

            // TOS? See http://en.wikipedia.org/wiki/TCP_offload_engine
            if (TotalLength == 0)
            {
                TotalLength = header.Length;
            }

            // Check that the TotalLength is valid, at least HeaderMinimumLength long
            if (TotalLength < HeaderMinimumLength)
            {
                throw new System.InvalidOperationException("TotalLength " + TotalLength + " < HeaderMinimumLength " + HeaderMinimumLength);
            }

            // update the header length with the correct value
            // NOTE: we take care to convert from 32bit words into bytes
            // NOTE: we do this *after* setting header because we need header to be valid
            //       before we can retrieve the HeaderLength property
            header.Length = HeaderLength * 4;

            log.DebugFormat("IPv4Packet HeaderLength {0}", HeaderLength);
            log.DebugFormat("header {0}", header);

            // parse the payload
            var payload = header.EncapsulatedBytes(PayloadLength);

            payloadPacketOrData = IpPacket.ParseEncapsulatedBytes(payload,
                                                                  NextHeader,
                                                                  this);
        }
예제 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bas">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        public IPv6Packet(ByteArraySegment bas)
        {
            log.Debug(bas.ToString());

            // slice off the header
            header        = new ByteArraySegment(bas);
            header.Length = IPv6Packet.HeaderMinimumLength;

            // set the actual length, we need to do this because we need to set
            // header to something valid above before we can retrieve the PayloadLength
            log.DebugFormat("PayloadLength: {0}", PayloadLength);
            header.Length = bas.Length - PayloadLength;

            // parse the payload
            var payload = header.EncapsulatedBytes(PayloadLength);

            payloadPacketOrData = IpPacket.ParseEncapsulatedBytes(payload,
                                                                  NextHeader,
                                                                  this);
        }