mirror of https://github.com/secdev/scapy.git
Merge pull request #1024 from p-l-/fix-macos-pcapdnet
Fix Travis/OSX tests with PCAPDNET
This commit is contained in:
commit
676a37481a
|
@ -7,14 +7,16 @@
|
||||||
Routing and handling of network interfaces.
|
Routing and handling of network interfaces.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from scapy.utils import atol, ltoa, itom, pretty_list
|
|
||||||
|
|
||||||
from scapy.config import conf
|
from scapy.config import conf
|
||||||
|
from scapy.consts import WINDOWS, LOOPBACK_INTERFACE
|
||||||
from scapy.error import Scapy_Exception, warning
|
from scapy.error import Scapy_Exception, warning
|
||||||
from scapy.arch import get_working_if
|
from scapy.modules import six
|
||||||
from scapy.consts import WINDOWS
|
from scapy.utils import atol, ltoa, itom, pretty_list
|
||||||
import scapy.consts
|
|
||||||
import scapy.modules.six as six
|
|
||||||
|
|
||||||
##############################
|
##############################
|
||||||
## Routing/Interfaces stuff ##
|
## Routing/Interfaces stuff ##
|
||||||
|
@ -62,7 +64,7 @@ class Route:
|
||||||
nhop = gw
|
nhop = gw
|
||||||
else:
|
else:
|
||||||
nhop = thenet
|
nhop = thenet
|
||||||
dev,ifaddr,x = self.route(nhop)
|
dev, ifaddr, _ = self.route(nhop)
|
||||||
else:
|
else:
|
||||||
ifaddr = get_if_addr(dev)
|
ifaddr = get_if_addr(dev)
|
||||||
return (atol(thenet), itom(msk), gw, dev, ifaddr, metric)
|
return (atol(thenet), itom(msk), gw, dev, ifaddr, metric)
|
||||||
|
@ -154,13 +156,15 @@ class Route:
|
||||||
continue
|
continue
|
||||||
aa = atol(a)
|
aa = atol(a)
|
||||||
if aa == dst:
|
if aa == dst:
|
||||||
pathes.append((0xffffffff, 1, (scapy.consts.LOOPBACK_INTERFACE,a,"0.0.0.0")))
|
pathes.append(
|
||||||
|
(0xffffffff, 1, (LOOPBACK_INTERFACE, a, "0.0.0.0"))
|
||||||
|
)
|
||||||
if (dst & m) == (d & m):
|
if (dst & m) == (d & m):
|
||||||
pathes.append((m, me, (i,a,gw)))
|
pathes.append((m, me, (i,a,gw)))
|
||||||
if not pathes:
|
if not pathes:
|
||||||
if verbose:
|
if verbose:
|
||||||
warning("No route found (no default route?)")
|
warning("No route found (no default route?)")
|
||||||
return scapy.consts.LOOPBACK_INTERFACE,"0.0.0.0","0.0.0.0"
|
return LOOPBACK_INTERFACE, "0.0.0.0", "0.0.0.0"
|
||||||
# Choose the more specific route
|
# Choose the more specific route
|
||||||
# Sort by greatest netmask
|
# Sort by greatest netmask
|
||||||
pathes.sort(key=lambda x: x[0], reverse=True)
|
pathes.sort(key=lambda x: x[0], reverse=True)
|
||||||
|
@ -188,10 +192,12 @@ class Route:
|
||||||
|
|
||||||
conf.route=Route()
|
conf.route=Route()
|
||||||
|
|
||||||
#XXX use "with"
|
iface = conf.route.route("0.0.0.0", verbose=0)[0]
|
||||||
_betteriface = conf.route.route("0.0.0.0", verbose=0)[0]
|
|
||||||
if ((_betteriface if (isinstance(_betteriface, six.string_types) or _betteriface is None) else _betteriface.name) != scapy.consts.LOOPBACK_NAME):
|
if (iface.name if hasattr(iface, "name") else iface) == LOOPBACK_INTERFACE:
|
||||||
conf.iface = _betteriface
|
from scapy.arch import get_working_if
|
||||||
else:
|
|
||||||
conf.iface = get_working_if()
|
conf.iface = get_working_if()
|
||||||
del(_betteriface)
|
else:
|
||||||
|
conf.iface = iface
|
||||||
|
|
||||||
|
del iface
|
||||||
|
|
Loading…
Reference in New Issue