/// <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); }
/// <summary> /// Constructor /// </summary> /// <param name="bas"> /// A <see cref="ByteArraySegment"/> /// </param> public IPv4Packet(ByteArraySegment bas) { log.Debug(""); header = new ByteArraySegment(bas); RandomUtils.EnsurePacketLength(this, IPv4Fields.HeaderLength, header.Length); // TOS? See http://en.wikipedia.org/wiki/TCP_offload_engine if (TotalLength == 0) { TotalLength = header.Length; } // 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 RandomUtils.EnsurePacketLength(this, HeaderLength * 4, header.Length); 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); }
private void sendPackage(PacketDotNet.Packet udpPacket) { foreach (PcapDevice device in SharpPcap.CaptureDeviceList.Instance) { PacketDotNet.Packet p = udpPacket;// = new PacketDotNet.UdpPacket();// PacketDotNet.IpPacket packageip = (PacketDotNet.IpPacket)udpPacket; //p.EthernetProtocol = EthernetProtocols_Fields.IP; //p.IPVersion = IPVersions_Fields.IPV4; //p.IPProtocol = IPProtocols_Fields.UDP;// //p.TimeToLive = 2;// //p.IPHeaderLength = IPFields_Fields.IP_HEADER_LEN;// //p.Length = 60;// //p.SourceHwAddress = strSouMac; //p.DestinationHwAddress = strGateWayMac; //p.SourceAddress = "201.23.12.88"; //p.SourcePort = 12345; //p.DestinationAddress = "192.168.100.106"; //p.DestinationPort = 9000; //p.ComputeIPChecksum(true);// //p.ComputeUDPChecksum(true); p.PayloadPacket.PayloadPacket.PayloadData[0] = 0x10; p.PayloadPacket.PayloadPacket.UpdateCalculatedValues(); device.SendPacket(p.Bytes); } }
public IPv4Packet(byte[] Bytes, int Offset, PosixTimeval Timeval) : base(Timeval) { base.header = new ByteArraySegment(Bytes, Offset, Bytes.Length - Offset); if (this.TotalLength < 20) { object[] objArray1 = new object[] { "TotalLength ", this.TotalLength, " < HeaderMinimumLength ", 20 }; throw new InvalidOperationException(string.Concat(objArray1)); } base.header.Length = this.HeaderLength * 4; base.payloadPacketOrData = IpPacket.ParseEncapsulatedBytes(base.header, this.NextHeader, Timeval, this); }
/// <summary> /// Constructor /// </summary> /// <param name="bas"> /// A <see cref="ByteArraySegment"/> /// </param> public IPv6Packet(ByteArraySegment bas) { // 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 header.Length = bas.Length - PayloadLength; // parse the payload var payload = header.EncapsulatedBytes(PayloadLength); payloadPacketOrData = IpPacket.ParseEncapsulatedBytes(payload, NextHeader, this); }
/// <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); RandomUtils.EnsurePacketLength(this, IPv6Fields.HeaderLength, header.Length); 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); RandomUtils.EnsurePacketLength(this, IPv6Packet.HeaderMinimumLength, bas.Length - PayloadLength); header.Length = bas.Length - PayloadLength; // parse the payload var payload = header.EncapsulatedBytes(PayloadLength); payloadPacketOrData = IpPacket.ParseEncapsulatedBytes(payload, NextHeader, this); }
/// <summary> /// Constructor /// </summary> /// <param name="bas"> /// A <see cref="ByteArraySegment"/> /// </param> public IPv4Packet(ByteArraySegment bas) { header = new ByteArraySegment(bas); // 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; // parse the payload var payload = header.EncapsulatedBytes(PayloadLength); payloadPacketOrData = IpPacket.ParseEncapsulatedBytes(payload, NextHeader, this); }
public IPv6Packet(byte[] Bytes, int Offset, PosixTimeval Timeval) : base(Timeval) { base.header = new ByteArraySegment(Bytes, Offset, 40); base.header.Length = (Bytes.Length - Offset) - this.PayloadLength; base.payloadPacketOrData = IpPacket.ParseEncapsulatedBytes(base.header, this.NextHeader, Timeval, this); }