Ejemplo n.º 1
0
 /// <summary>
 /// Private constructor used for deserialization.
 /// </summary>
 private IpPacket(IpVersion version, byte ihl, byte dscp, ushort totalLength,
                  ushort identification, IpFlag flags, ushort fragmentOffset,
                  byte ttl, IpProtocol protocol, ushort checksum, IpAddress source,
                  IpAddress destination)
 {
     destination.ThrowIfNull("destination");
     source.ThrowIfNull("source");
     if (ihl > 0x0F)
     {
         throw new ArgumentException("The Internet Header Length field must " +
                                     "be in the range from 0 to 15.", nameof(ihl));
     }
     if (fragmentOffset > 0x1FFF)
     {
         throw new ArgumentException("The Fragment Offset field must be in " +
                                     "the range from 0 to 8191.", nameof(fragmentOffset));
     }
     Version        = version;
     Ihl            = ihl;
     Dscp           = dscp;
     TotalLength    = totalLength;
     Identification = identification;
     Flags          = flags;
     FragmentOffset = fragmentOffset;
     TimeToLive     = ttl;
     Protocol       = protocol;
     Checksum       = checksum;
     Source         = source;
     Destination    = destination;
     Data           = new byte[0];
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the IpPacket class using the specified
 /// values.
 /// </summary>
 /// <param name="destination">The IPv4 address of the destination
 /// host.</param>
 /// <param name="source">The IPv4 address of the sending host.</param>
 /// <param name="type">The type of the transport protocol encapsulated in
 /// the IP packet's data section.</param>
 /// <param name="fragmentOffset">The fragment offset of the packet.</param>
 /// <param name="data">The transport data to transfer as part of the IP
 /// packet.</param>
 /// <param name="ihl">The Internet Header Length.</param>
 /// <param name="dscp">The Differentiated Services Code Point.</param>
 /// <param name="ttl">The time-to-live of the IP packet.</param>
 /// <param name="identification">The idenfication used for uniquely identifying
 /// fragments of a fragmented IP packet.</param>
 /// <param name="flags">The flags set on the IP packet.</param>
 /// <exception cref="ArgumentNullException">Thrown if any of the arguments
 /// is null.</exception>
 public IpPacket(IpAddress destination, IpAddress source,
                 IpProtocol type, byte ihl, byte dscp, byte ttl, ushort identification,
                 IpFlag flags, ushort fragmentOffset, byte[] data)
 {
     destination.ThrowIfNull("destination");
     source.ThrowIfNull("source");
     data.ThrowIfNull("data");
     if (ihl > 0x0F)
     {
         throw new ArgumentException("The Internet Header Length field must " +
                                     "be in the range from 0 to 15.", nameof(ihl));
     }
     if (fragmentOffset > 0x1FFF)
     {
         throw new ArgumentException("The Fragment Offset field must be in " +
                                     "the range from 0 to 8191.", nameof(fragmentOffset));
     }
     Version        = IpVersion.Ipv4;
     Ihl            = ihl;
     Dscp           = dscp;
     Identification = identification;
     Flags          = flags;
     FragmentOffset = fragmentOffset;
     TimeToLive     = ttl;
     Protocol       = type;
     Source         = source;
     Destination    = destination;
     Data           = data;
     TotalLength    = (ushort)(20 + Data.Length);
     Checksum       = ComputeChecksum(this);
 }
Ejemplo n.º 3
0
		/// <summary>
		/// Private constructor used for deserialization.
		/// </summary>
		private IpPacket(IpVersion version, byte ihl, byte dscp, ushort totalLength,
			ushort identification, IpFlag flags, ushort fragmentOffset,
			byte ttl, IpProtocol protocol, ushort checksum, IpAddress source,
			IpAddress destination) {
			destination.ThrowIfNull("destination");
			source.ThrowIfNull("source");
			if (ihl > 0x0F)
				throw new ArgumentException("The Internet Header Length field must " +
					"be in the range from 0 to 15.", nameof(ihl));
			if (fragmentOffset > 0x1FFF)
				throw new ArgumentException("The Fragment Offset field must be in " +
					"the range from 0 to 8191.", nameof(fragmentOffset));
			Version = version;
			Ihl = ihl;
			Dscp = dscp;
			TotalLength = totalLength;
			Identification = identification;
			Flags = flags;
			FragmentOffset = fragmentOffset;
			TimeToLive = ttl;
			Protocol = protocol;
			Checksum = checksum;
			Source = source;
			Destination = destination;
			Data = new byte[0];
		}
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the IpPacket class using the specified
        /// values.
        /// </summary>
        /// <param name="destination">The IPv4 address of the destination
        /// host.</param>
        /// <param name="source">The IPv4 address of the sending host.</param>
        /// <param name="type">The type of the transport protocol encapsulated in
        /// the IP packet's data section.</param>
        /// <param name="fragmentOffset">The fragment offset of the packet.</param>
        /// <param name="data">The transport data to transfer as part of the IP
        /// packet.</param>
        /// <param name="ihl">The Internet Header Length.</param>
        /// <param name="dscp">The Differentiated Services Code Point.</param>
        /// <param name="ttl">The time-to-live of the IP packet.</param>
        /// <param name="identification">The idenfication used for uniquely identifying
        /// fragments of a fragmented IP packet.</param>
        /// <param name="flags">The flags set on the IP packet.</param>
        /// <exception cref="ArgumentNullException">Thrown if any of the arguments
        /// is null.</exception>
        public IpPacket(IpAddress destination, IpAddress source,
			IpProtocol type, byte ihl, byte dscp, byte ttl, ushort identification,
			IpFlag flags, ushort fragmentOffset, byte[] data) {
			destination.ThrowIfNull("destination");
			source.ThrowIfNull("source");
			data.ThrowIfNull("data");
			if (ihl > 0x0F)
				throw new ArgumentException("The Internet Header Length field must " +
					"be in the range from 0 to 15.", nameof(ihl));
			if (fragmentOffset > 0x1FFF)
				throw new ArgumentException("The Fragment Offset field must be in " +
					"the range from 0 to 8191.", nameof(fragmentOffset));
			Version = IpVersion.Ipv4;
			Ihl = ihl;
			Dscp = dscp;
			Identification = identification;
			Flags = flags;
			FragmentOffset = fragmentOffset;
			TimeToLive = ttl;
			Protocol = type;
			Source = source;
			Destination = destination;
			Data = data;
			TotalLength = (ushort) (20 + Data.Length);
			Checksum = ComputeChecksum(this);
		}