private void TCPHandler(ref byte[] PacketData) { TCPData TCP = new TCPData(); IPHandler(TCP, ref PacketData); byte[] p_TCPData = new byte[(PacketData.Length - TCP.IP_IHL)]; Buffer.BlockCopy(PacketData, TCP.IP_IHL, p_TCPData, 0, p_TCPData.Length); TCP.TCP_SourcePort = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 0)); TCP.TCP_DestinationPort = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 2)); TCP.TCP_SequenceNumber = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 4)); TCP.TCP_AcknowledgementNumber = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 8)); TCP.TCP_DataOffset = (byte)((p_TCPData[12] >> 4) * 4); TCP.TCP_ControlBits = (byte)((p_TCPData[13] & 0x3F)); TCP.TCP_Window = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 14)); TCP.TCP_Checksum = (ushort)(IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 16))); TCP.TCP_UrgentPointer = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 18)); if (!((TCP.TCP_DataOffset - 20) <= 0)) { byte[] p_TCPOptions = new byte[TCP.TCP_DataOffset - 20]; Buffer.BlockCopy(p_TCPData, 20, p_TCPOptions, 0, p_TCPOptions.Length); TCP.TCP_OptionsCreate(ref p_TCPOptions); } if (!((TCP.IP_TotalLength - (TCP.TCP_DataOffset + TCP.IP_IHL)) <= 0)) { byte[] p_DataSend = new byte[TCP.IP_TotalLength - (TCP.TCP_DataOffset + TCP.IP_IHL)]; Buffer.BlockCopy(p_TCPData, TCP.TCP_DataOffset, p_DataSend, 0, p_DataSend.Length); TCP.PacketDataCreate(ref p_DataSend); PRE.fire(TCP); } else { return; } }
private void TCPHandler(ref byte[] PacketData) { TCPData TCP = new TCPData(); IPHandler(TCP, ref PacketData); byte[] p_TCPData = new byte[(PacketData.Length - TCP.IP_IHL)]; Buffer.BlockCopy(PacketData, TCP.IP_IHL, p_TCPData, 0, p_TCPData.Length); TCP.TCP_SourcePort = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 0)); TCP.TCP_DestinationPort = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 2)); TCP.TCP_SequenceNumber = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 4)); TCP.TCP_AcknowledgementNumber = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 8)); TCP.TCP_DataOffset = (byte)((p_TCPData[12] >> 4) * 4); TCP.TCP_ControlBits = (byte)((p_TCPData[13] & 0x3F)); TCP.TCP_Window = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 14)); TCP.TCP_Checksum = (ushort)(IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 16))); TCP.TCP_UrgentPointer = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(p_TCPData, 18)); if (!((TCP.TCP_DataOffset - 20) <= 0)) { byte[] p_TCPOptions = new byte[TCP.TCP_DataOffset - 20]; Buffer.BlockCopy(p_TCPData, 20, p_TCPOptions, 0, p_TCPOptions.Length); TCP.TCP_OptionsCreate(ref p_TCPOptions); } if (!((TCP.IP_TotalLength - (TCP.TCP_DataOffset + TCP.IP_IHL)) <= 0)) { byte[] p_DataSend = new byte[TCP.IP_TotalLength - (TCP.TCP_DataOffset + TCP.IP_IHL)]; Buffer.BlockCopy(p_TCPData, TCP.TCP_DataOffset, p_DataSend, 0, p_DataSend.Length); TCP.PacketDataCreate(ref p_DataSend); PRE.fire(TCP); }else return; }