Arch: factor LOOPBACK_NAME const

This avoids a circular import problem affecting Windows platforms.
This commit is contained in:
Pierre LALET 2016-09-26 20:24:23 +02:00
parent 32b710444f
commit d466c17729
7 changed files with 8 additions and 18 deletions

View File

@ -10,7 +10,7 @@ Operating system specific functionality.
import socket
from scapy.arch.consts import LINUX, OPENBSD, FREEBSD, NETBSD, DARWIN, \
SOLARIS, WINDOWS, BSD, X86_64, ARM_64
SOLARIS, WINDOWS, BSD, X86_64, ARM_64, LOOPBACK_NAME
from scapy.error import *
import scapy.config
from scapy.pton_ntop import inet_pton
@ -73,7 +73,6 @@ if LINUX:
if scapy.config.conf.use_pcap or scapy.config.conf.use_dnet:
from scapy.arch.pcapdnet import *
elif BSD:
from scapy.arch.bsd import LOOPBACK_NAME
from scapy.arch.unix import read_routes, read_routes6, in6_getifaddr
scapy.config.conf.use_pcap = True
scapy.config.conf.use_dnet = True

View File

@ -1,10 +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
"""
Support for BSD-like operating systems such as FreeBSD, OpenBSD and Mac OS X.
"""
LOOPBACK_NAME = "lo0"

View File

@ -22,3 +22,5 @@ else:
uname = os.uname()
X86_64 = uname[4] == 'x86_64'
ARM_64 = uname[4] == 'aarch64'
LOOPBACK_NAME = "lo" if LINUX else "lo0"

View File

@ -12,6 +12,7 @@ import sys,os,struct,socket,time
from select import select
from fcntl import ioctl
from scapy.arch.consts import LOOPBACK_NAME
import scapy.utils
import scapy.utils6
from scapy.packet import Packet, Padding
@ -81,8 +82,6 @@ PACKET_FASTROUTE = 6 # Fastrouted frame
# Unused, PACKET_FASTROUTE and PACKET_LOOPBACK are invisible to user space
LOOPBACK_NAME="lo"
with os.popen("%s -V 2> /dev/null" % conf.prog.tcpdump) as _f:
if _f.close() >> 8 == 0x7f:
log_loading.warning("Failed to execute tcpdump. Check it is installed and in the PATH")

View File

@ -11,6 +11,4 @@ Customization for the Solaris operation system.
import socket
socket.IPPROTO_GRE = 47
LOOPBACK_NAME="lo0"
from scapy.arch.unix import *

View File

@ -13,6 +13,7 @@ import subprocess as sp
from glob import glob
import tempfile
from scapy.arch.consts import LOOPBACK_NAME
from scapy.config import conf,ConfClass
from scapy.error import Scapy_Exception,log_loading,log_runtime
from scapy.utils import atol, itom, inet_aton, inet_ntoa, PcapReader
@ -38,7 +39,6 @@ if not hasattr(socket, 'IPPROTO_ESP'):
from scapy.arch import pcapdnet
from scapy.arch.pcapdnet import *
LOOPBACK_NAME="lo0"
WINDOWS = True
def _exec_query_ps(cmd, fields):

View File

@ -8,7 +8,7 @@ Routing and handling of network interfaces.
"""
import socket
from scapy.arch import read_routes,get_if_addr,LOOPBACK_NAME
from scapy.arch.consts import LOOPBACK_NAME
from scapy.utils import atol,ltoa,itom
from scapy.config import conf
from scapy.error import Scapy_Exception,warning
@ -26,6 +26,7 @@ class Route:
self.cache = {}
def resync(self):
from scapy.arch import read_routes
self.invalidate_cache()
self.routes = read_routes()
@ -40,6 +41,7 @@ class Route:
return rt
def make_route(self, host=None, net=None, gw=None, dev=None):
from scapy.arch import get_if_addr
if host is not None:
thenet,msk = host,32
elif net is not None: