From d6d61091d0eab1f3c00d65461ffadb2440450d43 Mon Sep 17 00:00:00 2001 From: Corentin Henry <corentinhenry@gmail.com> Date: Wed, 9 Sep 2015 09:53:10 -0700 Subject: [PATCH] Fix packet generator for classes inheritating from list SetGen is broken for custom list classes as illustrated by the following example: >>> packet = Ether() / IP() >>> packet_list = [packet, packet] >>> sendp(packet_list) .. Sent 2 packets. >>> # Now let's do the same with a custom class >>> class MyList(list): pass ... >>> weird_packet_list = MyList(packet_list) >>> len(weird_packet_list) 2 >>> sendp(weird_packet_list) . Sent 1 packets. >>> # Only one packet is sent instead of two. >>> # This is due to SetGen using type() instead of insinstance() to check >>> # the nature of the arguments. Indeed: >>> type(weird_packet_list) <class 'scapy.all.MyList'> >>> isinstance(weird_packet_list, list) True --HG-- extra : rebase_source : aeb2b7bd46f3cb4cf0491bbea4a38157e93ecb71 --- scapy/base_classes.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scapy/base_classes.py b/scapy/base_classes.py index e54428a2..3fa05486 100644 --- a/scapy/base_classes.py +++ b/scapy/base_classes.py @@ -22,9 +22,7 @@ class Gen(object): class SetGen(Gen): def __init__(self, set, _iterpacket=1): self._iterpacket=_iterpacket - if type(set) is list: - self.set = set - elif isinstance(set, BasePacketList): + if isinstance(set, (list, BasePacketList)): self.set = list(set) else: self.set = [set] -- GitLab