Skip to content
Lucio Santi edited this page Aug 1, 2014 · 2 revisions

PTC WikiCode overviewpacket

This module provides the PTCPacket class that implements, not surprisingly, the PTC packet. Every field of the packet is mapped to a setter method. IP addresses can be defined as well, as the following code snippet shows:

>>> packet = PTCPacket()
>>> packet.set_source_ip('192.168.0.1')
>>> packet.set_destination_ip('192.168.0.100')
>>> packet.set_source_port(12345)
>>> packet.set_destination_port(80)
>>> packet.set_seq_number(8989)
>>> packet.add_flag(SYNFlag)
>>> packet.set_payload('hola!')
>>> packet.set_window_size(1024)
>>> packet
From: (192.168.0.1, 12345)
To: (192.168.0.100, 80)
Seq: 8989
Ack: 0
Flags: SYN
Window: 1024
Payload: hola!
>>> packet.get_ack_number()
0
>>> packet.get_seq_number()
8989
>>> # This method informs the interval of sequence numbers
>>> # consumed by this packet (#SEQ + |payload|).
>>> packet.get_seq_interval()
(8989, 8994)

The in operator can be used in order to find out if some flag is enabled:

>>> ACKFlag in packet
False
>>> SYNFlag in packet
True
>>> FINFlag in packet
False

Clone this wiki locally