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();
        }
Beispiel #2
0
        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();
        }
        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();
        }
Beispiel #4
0
        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();
        }