/*
This file is part of PacketDotNet
PacketDotNet is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PacketDotNet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PacketDotNet. If not, see .
*/
/*
* Copyright 2009 Chris Morgan
*/
namespace PacketDotNet
{
///
/// IP protocol field encoding information.
///
public struct IPv4Fields
{
/// Width of the IP version and header length field in bytes.
public readonly static int VersionAndHeaderLengthLength = 1;
/// Width of the Differentiated Services / Type of service field in bytes.
public readonly static int DifferentiatedServicesLength = 1;
/// Width of the total length field in bytes.
public readonly static int TotalLengthLength = 2;
/// Width of the ID field in bytes.
public readonly static int IdLength = 2;
/// Width of the fragment offset bits and offset field in bytes.
public readonly static int FragmentOffsetAndFlagsLength = 2;
/// Width of the TTL field in bytes.
public readonly static int TtlLength = 1;
/// Width of the IP protocol code in bytes.
public readonly static int ProtocolLength = 1;
/// Width of the IP checksum in bytes.
public readonly static int ChecksumLength = 2;
/// Position of the version code and header length within the IP header.
public readonly static int VersionAndHeaderLengthPosition = 0;
/// Position of the differentiated services value within the IP header.
public readonly static int DifferentiatedServicesPosition;
/// Position of the header length within the IP header.
public readonly static int TotalLengthPosition;
/// Position of the packet ID within the IP header.
public readonly static int IdPosition;
/// Position of the flag bits and fragment offset within the IP header.
public readonly static int FragmentOffsetAndFlagsPosition;
/// Position of the ttl within the IP header.
public readonly static int TtlPosition;
///
/// Position of the protocol used within the IP data
///
public readonly static int ProtocolPosition;
/// Position of the checksum within the IP header.
public readonly static int ChecksumPosition;
/// Position of the source IP address within the IP header.
public readonly static int SourcePosition;
/// Position of the destination IP address within a packet.
public readonly static int DestinationPosition;
/// Length in bytes of an IP header, excluding options.
public readonly static int HeaderLength; // == 20
///
/// Number of bytes in an IPv4 address
///
public readonly static int AddressLength = 4;
static IPv4Fields()
{
DifferentiatedServicesPosition = VersionAndHeaderLengthPosition + VersionAndHeaderLengthLength;
TotalLengthPosition = DifferentiatedServicesPosition + DifferentiatedServicesLength;
IdPosition = TotalLengthPosition + TotalLengthLength;
FragmentOffsetAndFlagsPosition = IdPosition + IdLength;
TtlPosition = FragmentOffsetAndFlagsPosition + FragmentOffsetAndFlagsLength;
ProtocolPosition = TtlPosition + TtlLength;
ChecksumPosition = ProtocolPosition + ProtocolLength;
SourcePosition = ChecksumPosition + ChecksumLength;
DestinationPosition = SourcePosition + AddressLength;
HeaderLength = DestinationPosition + AddressLength;
}
}
}