Repository: secdev/scapy

Issue:
dnet module renamed
On Debian/Ubuntu, the dnet module was renamed dumbnet. This makes Scapy dnet related code unusable ... Their behavior is also slightly different ...



Discussion:

Resolving patch:
diff --git a/scapy/arch/pcapdnet.py b/scapy/arch/pcapdnet.py
--- a/scapy/arch/pcapdnet.py
+++ b/scapy/arch/pcapdnet.py
@@ -12,7 +12,7 @@
     from fcntl import ioctl
 from scapy.data import *
 from scapy.config import conf
-from scapy.utils import warning
+from scapy.utils import warning, mac2str
 from scapy.supersocket import SuperSocket
 from scapy.error import Scapy_Exception
 import scapy.arch
@@ -460,12 +460,15 @@ def send(self, x):
     
         conf.L2listen = L2pcapListenSocket
 
-        
-    
 
 if conf.use_dnet:
     try:
-        import dnet
+        try:
+            # First try to import dnet
+            import dnet
+        except ImportError:
+            # Then, try to import dumbnet as dnet
+            import dumbnet as dnet
     except ImportError,e:
         if conf.interactive:
             log_loading.error("Unable to import dnet module: %s" % e)
@@ -483,21 +486,41 @@ def get_if_list():
             raise
     else:
         def get_if_raw_hwaddr(iff):
+            """Return a tuple containing the link type and the raw hardware
+               address corresponding to the interface 'iff'"""
+
             if iff == scapy.arch.LOOPBACK_NAME:
-                return (772, '\x00'*6)
+                return (ARPHDR_LOOPBACK, '\x00'*6)
+
+            # Retrieve interface information
             try:
                 l = dnet.intf().get(iff)
-                l = l["link_addr"]
+                link_addr = l["link_addr"]
             except:
-                raise Scapy_Exception("Error in attempting to get hw address for interface [%s]" % iff)
-            return l.type,l.data
+                raise Scapy_Exception("Error in attempting to get hw address"
+                                      " for interface [%s]" % iff)
+
+            if hasattr(link_addr, "type"):
+                # Legacy dnet module
+                return link_addr.type, link_addr.data
+
+            else:
+                # dumbnet module
+                mac = mac2str(str(link_addr))
+
+                # Adjust the link type
+                if l["type"] == 6:  # INTF_TYPE_ETH from dnet
+                    return (ARPHDR_ETHER, mac)
+
+                return (l["type"], mac)
+
         def get_if_raw_addr(ifname):
             i = dnet.intf()
             return i.get(ifname)["addr"].data
         def get_if_list():
             return [i.get("name", None) for i in dnet.intf()]
-    
-    
+
+
 if conf.use_pcap and conf.use_dnet:
     class L3dnetSocket(SuperSocket):
         desc = "read/write packets at layer 3 using libdnet and libpcap"


Test patch:
diff --git a/test/regression.uts b/test/regression.uts
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -24,6 +24,20 @@ lsc()
 ~ conf
 conf.debug_dissector = True
 
+
+############
+############
++ Scapy functions tests
+
+= Interface related functions
+
+get_if_raw_hwaddr(conf.iface)
+
+get_if_raw_addr(conf.iface).encode("hex")
+
+get_if_list()
+
+
 ############
 ############
 + Basic tests