public TcpPacket HandleTcpPacket() { TcpPacket packet = new TcpPacket(); int source_port = HeaderParser.ToInt(this.Data, 0, 16); int dest_port = HeaderParser.ToInt(this.Data, 16, 16); int offset = HeaderParser.ToInt(this.Data, 96, 4) * 4; packet.Source = new IPEndPoint(this.Source, source_port); packet.Destination = new IPEndPoint(this.Destination, dest_port); packet.Sequence = HeaderParser.ToUInt(this.Data, 32, 32); packet.Acknowledgement = HeaderParser.ToUInt(this.Data, 64, 32); packet.DataOffset = offset; packet.Urgent = HeaderParser.ToByte(this.Data, 106, 1) != 0; packet.Ack = HeaderParser.ToByte(this.Data, 107, 1) != 0; packet.Push = HeaderParser.ToByte(this.Data, 108, 1) != 0; packet.Reset = HeaderParser.ToByte(this.Data, 109, 1) != 0; packet.Syn = HeaderParser.ToByte(this.Data, 110, 1) != 0; packet.Fin = HeaderParser.ToByte(this.Data, 111, 1) != 0; packet.WindowSize = HeaderParser.ToInt(this.Data, 112, 16); packet.Checksum = HeaderParser.ToInt(this.Data, 128, 16); packet.UrgentPointer = HeaderParser.ToInt(this.Data, 144, 16); if (offset > 20) { packet.SetData(this.Data, 20, offset - 20); } packet.SetData(this.Data, offset, this.Data.Length - offset); return(packet); }
private void HandleTcpPacket(byte[] data, IPAddress source, IPAddress destination) { TcpPacket packet = new TcpPacket(); int port = Sniffer.HeaderParser.ToInt(data, 0, 0x10); int num2 = Sniffer.HeaderParser.ToInt(data, 0x10, 0x10); int offset = Sniffer.HeaderParser.ToInt(data, 0x60, 4) * 4; packet.Source = new IPEndPoint(source, port); packet.Destination = new IPEndPoint(destination, num2); packet.Sequence = Sniffer.HeaderParser.ToUInt(data, 0x20, 0x20); packet.Acknowledgement = Sniffer.HeaderParser.ToUInt(data, 0x40, 0x20); packet.Urgent = Sniffer.HeaderParser.ToByte(data, 0x6a, 1) != 0; packet.Ack = Sniffer.HeaderParser.ToByte(data, 0x6b, 1) != 0; packet.Push = Sniffer.HeaderParser.ToByte(data, 0x6c, 1) != 0; packet.Reset = Sniffer.HeaderParser.ToByte(data, 0x6d, 1) != 0; packet.Syn = Sniffer.HeaderParser.ToByte(data, 110, 1) != 0; packet.Fin = Sniffer.HeaderParser.ToByte(data, 0x6f, 1) != 0; packet.SetData(data, offset, data.Length - offset); this.FireTcpPacketReceived(packet); }