Merge pull request #296 from p-l-/fix-circular-imports

Arch: move constant values to a new submodule
This commit is contained in:
Guillaume Valadon 2016-09-27 14:23:07 +02:00 committed by GitHub
commit 8e08beeab8
8 changed files with 36 additions and 34 deletions

View File

@ -7,9 +7,10 @@
Operating system specific functionality.
"""
import socket
import sys,os,socket
from scapy.arch.consts import LINUX, OPENBSD, FREEBSD, NETBSD, DARWIN, \
SOLARIS, WINDOWS, BSD, X86_64, ARM_64, LOOPBACK_NAME
from scapy.error import *
import scapy.config
from scapy.pton_ntop import inet_pton
@ -54,19 +55,6 @@ def get_if_hwaddr(iff):
raise Scapy_Exception("Unsupported address family (%i) for interface [%s]" % (addrfamily,iff))
LINUX = sys.platform.startswith("linux")
OPENBSD = sys.platform.startswith("openbsd")
FREEBSD = "freebsd" in sys.platform
NETBSD = sys.platform.startswith("netbsd")
DARWIN = sys.platform.startswith("darwin")
SOLARIS = sys.platform.startswith("sunos")
WINDOWS = sys.platform.startswith("win32")
BSD = DARWIN or FREEBSD or OPENBSD or NETBSD
X86_64 = not WINDOWS and (os.uname()[4] == 'x86_64')
ARM_64 = not WINDOWS and (os.uname()[4] == 'aarch64')
# Next step is to import following architecture specific functions:
# def get_if_raw_hwaddr(iff)
# def get_if_raw_addr(iff):
@ -85,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"

26
scapy/arch/consts.py Normal file
View File

@ -0,0 +1,26 @@
## 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
import os
from sys import platform
LINUX = platform.startswith("linux")
OPENBSD = platform.startswith("openbsd")
FREEBSD = "freebsd" in platform
NETBSD = platform.startswith("netbsd")
DARWIN = platform.startswith("darwin")
SOLARIS = platform.startswith("sunos")
WINDOWS = platform.startswith("win32")
BSD = DARWIN or FREEBSD or OPENBSD or NETBSD
if WINDOWS:
X86_64 = False
ARM_64 = False
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:

View File

@ -11,8 +11,8 @@ import errno
import cPickle,os,sys,time,subprocess
import itertools
from select import select
from scapy.arch.consts import DARWIN, FREEBSD
from scapy.data import *
from scapy import arch
from scapy.config import conf
from scapy.packet import Gen
from scapy.utils import warning,get_temp_file,PcapReader,wrpcap
@ -127,7 +127,7 @@ def sndrcv(pks, pkt, timeout = None, inter = 0, verbose=None, chainCC=0, retry=0
if remaintime <= 0:
break
r = None
if not isinstance(pks, StreamSocket) and (arch.FREEBSD or arch.DARWIN):
if not isinstance(pks, StreamSocket) and (FREEBSD or DARWIN):
inp, out, err = select(inmask,[],[], 0.05)
if len(inp) == 0 or pks in inp:
r = pks.nonblock_recv()