From 47bd4e29e2f7de9da45c0638b8980afeee792460 Mon Sep 17 00:00:00 2001 From: Pierre LALET <pierre.lalet@cea.fr> Date: Mon, 28 Aug 2017 14:50:53 +0200 Subject: [PATCH] Windows: remove compatibility submodule --- scapy/arch/__init__.py | 8 ---- scapy/arch/windows/__init__.py | 23 ++++++++--- scapy/arch/windows/compatibility.py | 16 -------- scapy/arch/windows/disable_sendrecv.py | 57 -------------------------- 4 files changed, 18 insertions(+), 86 deletions(-) delete mode 100644 scapy/arch/windows/compatibility.py delete mode 100644 scapy/arch/windows/disable_sendrecv.py diff --git a/scapy/arch/__init__.py b/scapy/arch/__init__.py index d76ba5b4..f8cb4bf9 100644 --- a/scapy/arch/__init__.py +++ b/scapy/arch/__init__.py @@ -68,14 +68,6 @@ elif SOLARIS: from scapy.arch.solaris import * elif WINDOWS: from scapy.arch.windows import * - # import only if parent is not route.py - # because compatibility.py will require route.py to work (through sendrecv.py) - parents = parent_function() - if len(parents) >= 3: - if not parents[2][1].endswith("route.py"): - from scapy.arch.windows.compatibility import * - else: - from scapy.arch.windows.compatibility import * if scapy.config.conf.iface is None: scapy.config.conf.iface = LOOPBACK_NAME diff --git a/scapy/arch/windows/__init__.py b/scapy/arch/windows/__init__.py index ade8935f..154a667f 100755 --- a/scapy/arch/windows/__init__.py +++ b/scapy/arch/windows/__init__.py @@ -423,7 +423,7 @@ class NetworkInterfaceDict(UserDict): except (KeyError, PcapNameNotFoundError): pass - if len(self.data) == 0 and conf.use_winpcapy: + if not self.data and conf.use_winpcapy: _detect = pcap_service_status() def _ask_user(): if not conf.interactive: @@ -692,7 +692,7 @@ def _append_route6(routes, dpref, dp, nh, iface, lifaddr): else: devaddrs = (x for x in lifaddr if x[2] == iface) cset = scapy.utils6.construct_source_candidate_set(dpref, dp, devaddrs) - if len(cset) == 0: + if not cset: return # APPEND (DESTINATION, NETMASK, NEXT HOP, IFACE, CANDIDATS) routes.append((dpref, dp, nh, iface, cset)) @@ -745,7 +745,7 @@ def _read_routes6_7(): index = 0 for l in stdout.split('\n'): if not l.strip(): - if len(current_object) == 0: + if not current_object: continue if len(current_object) == len(regex_list): @@ -836,10 +836,10 @@ def route_add_loopback(routes=None, ipv6=False, iflist=None): warning("This will completly mess up the routes. Testing purpose only !") # Add only if some adpaters already exist if ipv6: - if len(conf.route6.routes) == 0: + if not conf.route6.routes: return else: - if len(conf.route.routes) == 0: + if not conf.route.routes: return data = {} data['name'] = LOOPBACK_NAME @@ -884,3 +884,16 @@ def route_add_loopback(routes=None, ipv6=False, iflist=None): routes.append(loopback_route6_custom) else: routes.append(loopback_route) + + +if not conf.use_winpcapy: + + class NotAvailableSocket(SuperSocket): + desc = "wpcap.dll missing" + def __init__(self, *args, **kargs): + raise RuntimeError("Sniffing and sending packets is not available: " + "winpcap is not installed") + + conf.L2socket = NotAvailableSocket + conf.L2listen = NotAvailableSocket + conf.L3socket = NotAvailableSocket diff --git a/scapy/arch/windows/compatibility.py b/scapy/arch/windows/compatibility.py deleted file mode 100644 index 5038b8e9..00000000 --- a/scapy/arch/windows/compatibility.py +++ /dev/null @@ -1,16 +0,0 @@ -## This file is part of Scapy -## See http://www.secdev.org/projects/scapy for more informations -## Copyright (C) Philippe Biondi <phil@secdev.org> -## This program is published under a GPLv2 license - -""" -Instanciate part of the customizations needed to support Microsoft Windows. -""" - -from __future__ import absolute_import, print_function - -from scapy.config import conf - -# If wpcap.dll is not available -if not (conf.use_winpcapy or conf.use_pcap or conf.use_dnet): - from scapy.arch.windows.disable_sendrecv import * diff --git a/scapy/arch/windows/disable_sendrecv.py b/scapy/arch/windows/disable_sendrecv.py deleted file mode 100644 index e9d514c6..00000000 --- a/scapy/arch/windows/disable_sendrecv.py +++ /dev/null @@ -1,57 +0,0 @@ -## This file is part of Scapy -## See http://www.secdev.org/projects/scapy for more informations -## Copyright (C) Philippe Biondi <phil@secdev.org> -## This program is published under a GPLv2 license - -""" -When wpcap.dll is not available, replace all sendrecv functions that won't work. -""" - -from scapy.error import log_runtime -import scapy.sendrecv as sendrecv -import scapy.config as conf -from scapy.supersocket import SuperSocket - -def log_warning(): - if conf.conf.interactive: - log_runtime.warning("Function not available (winpcap is not installed)") - else: - raise ImportError("Function not available (winpcap is not installed)") - -def not_available(*args, **kwargs): - log_warning() - return None - -class not_available_socket(SuperSocket): - desc = "wpcap.dll missing" - def __init__(self, type=None, promisc=None, filter=None, iface=None, nofilter=0): - log_warning() - return - def send(self, x): - return - def recv(self,x=None): - return - def nonblock_recv(self): - return - def close(self): - return - - -sendrecv.send = not_available -sendrecv.sendp = not_available -sendrecv.sendpfast = not_available -sendrecv.sr = not_available -sendrecv.sr1 = not_available -sendrecv.srflood = not_available -sendrecv.srloop = not_available -sendrecv.srp = not_available -sendrecv.srp1 = not_available -sendrecv.srpflood = not_available -sendrecv.srploop = not_available -sendrecv.sniff = not_available -sendrecv.sndrcv = not_available -sendrecv.sndrcvflood = not_available -sendrecv.tshark = not_available - -conf.L3socket=not_available_socket -conf.L2socket=not_available_socket -- GitLab