File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,6 +68,26 @@ while not reader.is_exhausted():
6868 pass
6969```
7070
71+ ### Packet Data Lifetime
72+
73+ > ** Note:** Accessing ` packet.data ` returns a copy of the raw packet bytes as a Python ` bytes `
74+ > object. The copy is made each time the property is accessed. Internally, the ` Packet ` holds a
75+ > pointer into the ` PacketReader ` 's file buffer, so always access ` .data ` while the reader is
76+ > still alive:
77+
78+ ``` python
79+ # Safe: access .data while reader exists
80+ reader = fpcap.PacketReader(" capture.pcap" )
81+ for packet in reader:
82+ raw_bytes = packet.data # copies bytes — safe to keep
83+
84+ # Unsafe: accessing .data after the reader is destroyed
85+ reader = fpcap.PacketReader(" capture.pcap" )
86+ packets = list (reader)
87+ del reader
88+ packets[0 ].data # undefined behavior — reader's buffer is freed
89+ ```
90+
7191### Writing packets
7292
7393Copy packets from one file to another:
You can’t perform that action at this time.
0 commit comments