Exemple #1
0
        /// <summary>
        /// Simple constructor for the UDP header.
        /// </summary>
        public UdpHeader()
            : base()
        {
            srcPort = 0;
            destPort = 0;
            udpLength = 0;
            udpChecksum = 0;

            ipv6PacketHeader = null;
            ipv4PacketHeader = null;
        }
Exemple #2
0
        /// <summary>
        /// This routine creates an instance of the Ipv4Header class from a byte
        /// array that is a received IGMP packet. This is useful when a packet
        /// is received from the network and the header object needs to be
        /// constructed from those values.
        /// </summary>
        /// <param name="ipv4Packet">Byte array containing the binary IPv4 header</param>
        /// <param name="bytesCopied">Number of bytes used in header</param>
        /// <returns>Returns the Ipv4Header object created from the byte array</returns>
        public static Ipv4Header Create( byte[] ipv4Packet, ref int bytesCopied )
        {
            Ipv4Header ipv4Header = new Ipv4Header();

            // Make sure byte array is large enough to contain an IPv4 header
            if( ipv4Packet.Length < Ipv4Header.Ipv4HeaderLength )
                return null;

            // Decode the data in the array back into the class properties
            ipv4Header.ipVersion = (byte)((ipv4Packet[0] >> 4) & 0xF);
            ipv4Header.ipLength = (byte)(ipv4Packet[0] & 0xF);
            ipv4Header.ipTypeOfService = ipv4Packet[1];
            ipv4Header.ipTotalLength = BitConverter.ToUInt16( ipv4Packet, 2 );
            ipv4Header.ipId = BitConverter.ToUInt16( ipv4Packet, 4 );
            ipv4Header.ipOffset = BitConverter.ToUInt16( ipv4Packet, 6 );
            ipv4Header.ipTtl = ipv4Packet[8];
            ipv4Header.ipProtocol = ipv4Packet[9];
            ipv4Header.ipChecksum = BitConverter.ToUInt16( ipv4Packet, 10 );

            ipv4Header.ipSourceAddress = new IPAddress( BitConverter.ToUInt32( ipv4Packet, 12 ) );
            ipv4Header.ipDestinationAddress = new IPAddress( BitConverter.ToUInt32( ipv4Packet, 16 ) );

            bytesCopied = ipv4Header.Length;

            return ipv4Header;
        }