I need to pickle a
My solution (as inspired by the scapy mailing list) is as follows:
class PicklablePacket: """A container for scapy packets that can be pickled (in contrast to scapy packets themselves).""" def __init__(self, pkt): self.contents = str(pkt) self.time = pkt.time def __call__(self): """Get the original scapy packet.""" pkt = scapy.Ether(self.contents) pkt.time = self.time return pkt
Anywhere I wish to pass a
Packet through a
Queue I simply wrap it in a
__call__ it afterwards. I am not aware of data that is not retained this way. However this approach only works with
Ethernet packets. (All packets sniffed on a regular NIC (not WLAN) are Ethernet.) It could probably be extended to work for other types, too.