public static void MakeValid(TCPPacket tcp, IPVersions ipver) { tcp.IPVersion = ipver; tcp.IPProtocol = Packets.IPProtocol.IPProtocolType.TCP; tcp.TCPHeaderLength = TCPFields_Fields.TCP_HEADER_LEN; //Set the correct TCP header length if (ipver == IPVersions.IPv4) { // the total length of the ip packet is the size of all of the bytes in the packet // represented by tcp.Bytes, minus the link layer bytes // NOTE: this includes the ip header bytes, which is how the IPv4 total bytes // works tcp.IPTotalLength = tcp.Bytes.Length - LinkLayer.ProtocolOffset(LinkLayers.Ethernet10Mb); //Set the correct IP length tcp.IPHeaderLength = IPv4Fields_Fields.IP_HEADER_LEN; } else if (ipver == IPVersions.IPv6) { tcp.IPPayloadLength = tcp.Bytes.Length - EthernetFields_Fields.ETH_HEADER_LEN - IPv6Fields_Fields.IPv6_HEADER_LEN; } else { throw new System.InvalidOperationException("unknown ipver of " + ipver); } //Calculate checksums tcp.ComputeIPChecksum(); tcp.ComputeTCPChecksum(); }
public static TCPPacket RandomPacket(int size, IPVersions ipver) { if (size < 54) { throw new Exception("Size should be at least 54 (Eth + IP + TCP)"); } if (ipver == IPVersions.IPv6 && size < 74) { throw new Exception("Size should be at least 74 (Eth + IPv6 + TCP)"); } byte[] bytes = new byte[size]; SharpPcap.Util.Rand.Instance.GetBytes(bytes); TCPPacket tcp = new TCPPacket(14, bytes, true); MakeValid(tcp, ipver); return(tcp); }
public static TCPPacket RandomPacket(int size, IPVersions ipver) { if (size < MinimumIPv4Bytes) { throw new Exception("Size should be at least " + MinimumIPv4Bytes + " (Eth + IP + TCP)"); } if ((ipver == IPVersions.IPv6) && (size < MinimumIPv6Bytes)) { throw new Exception("Size should be at least " + MinimumIPv6Bytes + " (Eth + IPv6 + TCP)"); } byte[] bytes = new byte[size]; SharpPcap.Util.Rand.Instance.GetBytes(bytes); TCPPacket tcp = new TCPPacket(LinkLayer.ProtocolOffset(LinkLayers.Ethernet10Mb), bytes, true); MakeValid(tcp, ipver); return(tcp); }
private void InitIPPacket(IPVersions version) { ipv4 = null; ipv6 = null; if (version == IPVersions.IPv4) { ipv4 = new IPv4Packet(EthernetHeaderLength, Bytes); _ipPayloadOffset = _ethPayloadOffset + IPv4Fields_Fields.IP_HEADER_LEN; } else if (version == IPVersions.IPv6) { ipv6 = new IPv6Packet(EthernetHeaderLength, Bytes); _ipPayloadOffset = _ethPayloadOffset + IPv6Fields_Fields.IPv6_HEADER_LEN; } else { throw new System.InvalidOperationException("unknown IPVersions version of " + version); } }
private void InitIPPacket(IPVersions version) { ipv4 = null; ipv6 = null; if (version == IPVersions.IPv4) { ipv4 = new IPv4Packet(EthernetHeaderLength, Bytes); _ipOffset = _ethOffset + IPv4Fields_Fields.IP_HEADER_LEN; } else if (version == IPVersions.IPv6) { ipv6 = new IPv6Packet(EthernetHeaderLength, Bytes); _ipOffset = _ethOffset + IPv6Fields_Fields.IPv6_HEADER_LEN; } else { //lame default _ipOffset = _ethOffset; } }
public static void MakeValid(TCPPacket tcp, IPVersions ipver) { tcp.IPVersion = ipver; tcp.IPProtocol = Packets.IPProtocol.IPProtocolType.TCP; tcp.TCPHeaderLength = TCPFields_Fields.TCP_HEADER_LEN; //Set the correct TCP header length if (ipver == IPVersions.IPv4) { tcp.IPTotalLength = tcp.Bytes.Length - 14; //Set the correct IP length tcp.IPHeaderLength = IPv4Fields_Fields.IP_HEADER_LEN; } else if (ipver == IPVersions.IPv6) { tcp.IPPayloadLength = tcp.Bytes.Length - EthernetFields_Fields.ETH_HEADER_LEN - IPv6Fields_Fields.IPv6_HEADER_LEN; } else { } //Calculate checksums tcp.ComputeIPChecksum(); tcp.ComputeTCPChecksum(); }
/// <summary> Create a new IP packet. </summary> public IPPacket(int byteOffsetToEthernetPayload, byte[] bytes, IPVersions version) : base(byteOffsetToEthernetPayload, bytes) { IPVersion = version; }
/// <summary> Create a new IP packet.</summary> public IPPacket(int byteOffsetToEthernetPayload, byte[] bytes, Timeval tv, IPVersions version) : this(byteOffsetToEthernetPayload, bytes, version) { this._timeval = tv; }
/// <summary> Create a new IP packet.</summary> public IPPacket(int lLen, byte[] bytes, Timeval tv, IPVersions version) : this(lLen, bytes, version) { this._timeval = tv; }
public static TCPPacket RandomPacket(int size, IPVersions ipver) { if (size < MinimumIPv4Bytes) throw new Exception("Size should be at least " + MinimumIPv4Bytes + " (Eth + IP + TCP)"); if ((ipver == IPVersions.IPv6) && (size < MinimumIPv6Bytes)) throw new Exception("Size should be at least " + MinimumIPv6Bytes + " (Eth + IPv6 + TCP)"); byte[] bytes = new byte[size]; SharpPcap.Util.Rand.Instance.GetBytes(bytes); TCPPacket tcp = new TCPPacket(LinkLayer.ProtocolOffset(LinkLayers.Ethernet10Mb), bytes, true); MakeValid(tcp, ipver); return tcp; }
/// <summary> Create a new IP packet. </summary> public IPPacket(int lLen, byte[] bytes, IPVersions version) : base(lLen, bytes) { IPVersion = version; }
public IPPacket(IPVersions ipVersion, IPProtocol.IPProtocolType ipProtocolType, IPAddress sourceAddress, IPAddress destinationAddress, EthernetPacket ethernetPacket, byte[] ipPacketPayload) : base(EthernetFields_Fields.ETH_HEADER_LEN, null) { // determine how many bytes we need for this packet int ipHeaderLength = ((ipVersion == IPVersions.IPv4) ? IPv4Fields_Fields.IP_HEADER_LEN : IPv6Fields_Fields.IPv6_HEADER_LEN); int ipPayloadLength = (ipPacketPayload != null) ? ipPacketPayload.Length : 0; int totalBytesRequired = 0; totalBytesRequired += EthernetFields_Fields.ETH_HEADER_LEN; totalBytesRequired += ipHeaderLength; totalBytesRequired += ipPayloadLength; // copy the ethernet packet header into the byte array byte[] bytes = new Byte[totalBytesRequired]; Array.Copy(ethernetPacket.EthernetHeader, bytes, ethernetPacket.EthernetHeader.Length); // set the packet bytes to our new, correct length // buffer // // NOTE: we cannot say: Bytes = bytes; because // the Bytes set property results in a call to // InitIPPacket with a parameter of IPVersion which // would result in the version being retrieved from // an offset into the byte array but we haven't // set the version in the byte array yet by setting // this.IPVersion to a value base.Bytes = bytes; // call InitIPPacket to instantiate a packet of the proper type InitIPPacket(ipVersion); // set the header length to the default value for our ip version IPHeaderLength = ipHeaderLength; // set the EthernetPacket type to the proper ip version base.EthernetProtocol = (ipVersion == IPVersions.IPv4) ? EthernetPacketType.IPv4 : EthernetPacketType.IPv6; // set the ip protocol type this.IPProtocol = ipProtocolType; // set the current instance to the proper ip version this.IPVersion = ipVersion; // update the source and destination addresses this.SourceAddress = sourceAddress; this.DestinationAddress = destinationAddress; // and set the payload to the payload that was passed in if (ipPacketPayload != null) { Array.Copy(ipPacketPayload, 0, Bytes, _ipPayloadOffset, ipPacketPayload.Length); IPPayloadLength = ipPacketPayload.Length; } else { IPPayloadLength = 0; } }
public static TCPPacket RandomPacket(IPVersions ipver) { return(RandomPacket(ipver == IPVersions.IPv6 ? MinimumIPv6Bytes : MinimumIPv4Bytes, ipver)); }
public static TCPPacket RandomPacket(IPVersions ipver) { return RandomPacket(ipver==IPVersions.IPv6 ? 74:54, ipver); }
public static TCPPacket RandomPacket(int size, IPVersions ipver) { if(size<54) throw new Exception("Size should be at least 54 (Eth + IP + TCP)"); if(ipver == IPVersions.IPv6 && size < 74) throw new Exception("Size should be at least 74 (Eth + IPv6 + TCP)"); byte[] bytes = new byte[size]; SharpPcap.Util.Rand.Instance.GetBytes(bytes); TCPPacket tcp = new TCPPacket(14, bytes, true); MakeValid(tcp, ipver); return tcp; }
public static TCPPacket RandomPacket(IPVersions ipver) { return(RandomPacket(ipver == IPVersions.IPv6 ? 74:54, ipver)); }
public static TCPPacket RandomPacket(IPVersions ipver) { return RandomPacket(ipver == IPVersions.IPv6 ? MinimumIPv6Bytes : MinimumIPv4Bytes, ipver); }