-
- pkt = self._sock.recv(0x7fff)
- print 'Received packet on {0} of len {1}'.format(self._ifname, len(pkt))
- Ether(pkt).show2()
- print
-
- if ignore is not None:
- for i, ig_pkt in enumerate(ignore):
- # Auto pad all packets in ignore list
- ignore[i] = auto_pad(ig_pkt)
- for ig_pkt in ignore:
- if ig_pkt == pkt:
- # Found the packet in ignore list, get another one
- # TODO: subtract timeout - time_spent in here
- ignore.remove(ig_pkt)
- return self.recv(timeout, ignore)
-
- return Ether(pkt)
+ try:
+ with interruptingcow.timeout(timeout,
+ exception=RuntimeError('Timeout')):
+ ignore_list = list()
+ if ignore is not None:
+ for ig_pkt in ignore:
+ # Auto pad all packets in ignore list
+ ignore_list.append(auto_pad(ig_pkt))
+ while True:
+ pkt = self._sock.recv(0x7fff)
+ pkt_pad = auto_pad(pkt)
+ print 'Received packet on {0} of len {1}'\
+ .format(self._ifname, len(pkt))
+ if verbose:
+ pkt.show2() # pylint: disable=no-member
+ print
+ if pkt_pad in ignore_list:
+ ignore_list.remove(pkt_pad)
+ print 'Received packet ignored.'
+ continue
+ else:
+ return pkt
+ except RuntimeError:
+ return None