Arch: move constant values to a new submodule

This avoids a circular import problem affecting Windows platforms.
This commit is contained in:
Pierre LALET 2016-09-26 19:37:42 +02:00
parent 3d027710b7
commit 32b710444f
3 changed files with 29 additions and 17 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
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):

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

@ -0,0 +1,24 @@
## 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'

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()