From 7f82d8d9184916060cbc897d15be66fd1478ea9d Mon Sep 17 00:00:00 2001
From: Pierre LALET <pierre.lalet@cea.fr>
Date: Wed, 30 Aug 2017 17:55:32 +0200
Subject: [PATCH] BPF: use conf.default_l2 instead of Ether when type cannot be
 guessed

---
 scapy/arch/bpf/supersocket.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/scapy/arch/bpf/supersocket.py b/scapy/arch/bpf/supersocket.py
index e3a6b6d0..d4f48235 100644
--- a/scapy/arch/bpf/supersocket.py
+++ b/scapy/arch/bpf/supersocket.py
@@ -7,7 +7,6 @@ Scapy *BSD native support - BPF sockets
 from scapy.config import conf
 from scapy.error import Scapy_Exception, warning
 from scapy.supersocket import SuperSocket
-from scapy.layers.l2 import Ether
 from scapy.layers.inet import IP
 from scapy.layers.inet6 import IPv6
 from scapy.packet import Raw
@@ -121,20 +120,21 @@ class _L2bpfSocket(SuperSocket):
             ret = fcntl.ioctl(self.ins, BIOCGDLT, struct.pack('I', 0))
             ret = struct.unpack('I', ret)[0]
         except IOError as err:
-            warning("BIOCGDLT failed: unable to guess type. Using Ethernet !")
-            return Ether
+            cls = conf.default_l2
+            warning("BIOCGDLT failed: unable to guess type. Using %s !",
+                    cls.name)
+            return cls
 
         # *BSD loopback interface
         if OPENBSD and ret == 12:  # DTL_NULL on OpenBSD
             return Loopback
 
         # Retrieve the corresponding class
-        cls = conf.l2types.get(ret, None)
-        if cls is None:
-            cls = Ether
-            warning("Unable to guess type. Using Ethernet !")
-
-        return cls
+        try:
+            return conf.l2types[ret]
+        except KeyError:
+            cls = conf.default_l2
+            warning("Unable to guess type (type %i). Using %s", ret, cls.name)
 
     def set_nonblock(self, set_flag=True):
         """Set the non blocking flag on the socket"""
-- 
GitLab