From 1eaf474df268fb6637d63a6a9ef5a67c9f1f313e Mon Sep 17 00:00:00 2001
From: Dirk Loss <mail@dirk-loss.de>
Date: Mon, 20 Jul 2009 23:17:29 +0200
Subject: [PATCH] Support for special 'Scapy' variant of pypcap to enable
 timeouts

pylibpcap and pcapy offer a 'to_ms' parameter to set the read
timeout in milliseconds, but standard pypcap does not.
(Instead there is the 'immediate' parameter to disable buffering.)
A specially patched pcap version was made for Scapy which adds a
timeout_ms parameter, but to stay compatible with pypcap it has a
different position in the argument list than in pylibpcap
and pcapy.
So we have to distinguish four different Python bindings for
libpcap/WinPcap.
---
 scapy/arch/pcapdnet.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/scapy/arch/pcapdnet.py b/scapy/arch/pcapdnet.py
index d3fb250f..60fe7425 100644
--- a/scapy/arch/pcapdnet.py
+++ b/scapy/arch/pcapdnet.py
@@ -37,7 +37,17 @@ if conf.use_pcap:
         BIOCIMMEDIATE=-2147204496
 
         if hasattr(pcap,"pcap"): # python-pypcap
-            open_pcap = pcap.pcap
+            class _PcapWrapper_pypcap:
+                def __init__(self, device, snaplen, promisc, to_ms):
+                    # Normal pypcap module has no timeout parameter,
+                    # only the specially patched "scapy" variant has.                 
+                    if "scapy" in pcap.__version__.lower():
+                        self.pcap = pcap.pcap(device, snaplen, promisc, immediate=1, timeout_ms=to_ms)
+                    else:
+                        self.pcap = pcap.pcap(device, snaplen, promisc, immediate=1)                    
+                def __getattr__(self, attr):
+                    return getattr(self.pcap, attr)
+            open_pcap = lambda *args,**kargs: _PcapWrapper_pypcap(*args,**kargs)
         elif hasattr(pcap,"pcapObject"): # python-libpcap
             class _PcapWrapper_libpcap:
                 def __init__(self, *args, **kargs):
-- 
GitLab