This is the IPv4 protocol header.
Inheritance: AProtocolHeader
コード例 #1
0
ファイル: IPv4Header.cs プロジェクト: bpaziaud/Hermod
    /// <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>
    static public IPv4Header_old Create(byte[] ipv4Packet, ref int bytesCopied)
    {
        IPv4Header_old ipv4Header = new IPv4Header_old();

        // Make sure byte array is large enough to contain an IPv4 header
        if (ipv4Packet.Length < IPv4Header_old.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 IPv4Address(BitConverter.ToUInt32(ipv4Packet, 12));
        ipv4Header.ipDestinationAddress = new IPv4Address(BitConverter.ToUInt32(ipv4Packet, 16));

        bytesCopied = ipv4Header.Length;

        return(ipv4Header);
    }
コード例 #2
0
ファイル: UDPHeader.cs プロジェクト: bpaziaud/Hermod
    /// <summary>
    /// Simple constructor for the UDP header.
    /// </summary>
    public UdpHeader()
        : base()
    {
        srcPort     = 0;
        destPort    = 0;
        udpLength   = 0;
        udpChecksum = 0;

        ipv6PacketHeader = null;
        ipv4PacketHeader = null;
    }
コード例 #3
0
ファイル: UDPHeader.cs プロジェクト: Vanaheimr/Hermod
    /// <summary>
    /// Simple constructor for the UDP header.
    /// </summary>
    public UdpHeader()
        : base()
    {
        srcPort = 0;
        destPort = 0;
        udpLength = 0;
        udpChecksum = 0;

        ipv6PacketHeader = null;
        ipv4PacketHeader = null;
    }
コード例 #4
0
ファイル: IPv4Header.cs プロジェクト: Vanaheimr/Hermod
    /// <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_old Create(byte[] ipv4Packet, ref int bytesCopied)
    {
        IPv4Header_old ipv4Header = new IPv4Header_old();

        // Make sure byte array is large enough to contain an IPv4 header
        if (ipv4Packet.Length < IPv4Header_old.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 IPv4Address(BitConverter.ToUInt32(ipv4Packet, 12));
        ipv4Header.ipDestinationAddress = new IPv4Address(BitConverter.ToUInt32(ipv4Packet, 16));

        bytesCopied = ipv4Header.Length;

        return ipv4Header;
    }