def parse_from(self, packet_bytes): packet = PTCPacket() source_ip = self.parse_source_ip_on(packet_bytes) destination_ip = self.parse_destination_ip_on(packet_bytes) transport_packet_bytes = self.get_transport_packet_bytes_from(packet_bytes) source_port = self.parse_source_port_on(transport_packet_bytes) destination_port = self.parse_destination_port_on(transport_packet_bytes) seq_number = self.parse_seq_number_on(transport_packet_bytes) ack_number = self.parse_ack_number_on(transport_packet_bytes) flags = self.parse_flags_on(transport_packet_bytes) data = self.parse_data_on(transport_packet_bytes) packet.set_source_ip(source_ip) packet.set_destination_ip(destination_ip) packet.set_source_port(source_port) packet.set_destination_port(destination_port) packet.set_seq_number(seq_number) packet.set_ack_number(ack_number) packet.add_flags(flags) packet.set_payload(data) return packet
def build(self, payload=None, flags=None, seq=None, ack=None): packet = PTCPacket() source_address = self.control_block.get_source_address() source_port = self.control_block.get_source_port() dst_address = self.control_block.get_destination_address() dst_port = self.control_block.get_destination_port() packet.set_source_ip(source_address) packet.set_destination_ip(dst_address) packet.set_source_port(source_port) packet.set_destination_port(dst_port) if payload is not None: packet.set_payload(payload) if flags is not None: packet.add_flags(flags) if seq is not None: packet.set_seq_number(seq) if ack is not None: packet.set_ack_number(ack) return packet
def decode(self, packet_bytes): packet = PTCPacket() source_ip = self.decode_source_ip_on(packet_bytes) destination_ip = self.decode_destination_ip_on(packet_bytes) transport_bytes = self.get_transport_packet_bytes_from(packet_bytes) source_port = self.decode_source_port_on(transport_bytes) destination_port = self.decode_destination_port_on(transport_bytes) seq_number = self.decode_seq_number_on(transport_bytes) ack_number = self.decode_ack_number_on(transport_bytes) flags = self.decode_flags_on(transport_bytes) window_size = self.decode_window_size_on(transport_bytes) data = self.decode_data_on(transport_bytes) packet.set_source_ip(source_ip) packet.set_destination_ip(destination_ip) packet.set_source_port(source_port) packet.set_destination_port(destination_port) packet.set_seq_number(seq_number) packet.set_ack_number(ack_number) packet.add_flags(flags) packet.set_window_size(window_size) packet.set_payload(data) return packet
def build(self, payload=None, flags=None, seq=None, ack=None, window=None): packet = PTCPacket() packet.set_source_ip(self.source_address) packet.set_destination_ip(self.destination_address) packet.set_source_port(self.source_port) packet.set_destination_port(self.destination_port) if payload is not None: packet.set_payload(payload) if flags is not None: packet.add_flags(flags) if seq is not None: packet.set_seq_number(seq) if ack is not None: packet.set_ack_number(ack) if window is not None: packet.set_window_size(window) return packet