Skip to content
Snippets Groups Projects
Commit 2ec520aa authored by Guillaume Valadon's avatar Guillaume Valadon Committed by Pierre Lalet
Browse files

Scapy can now use dumbnet

parent 5a5bea6a
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ if not sys.platform.startswith("win"): ...@@ -12,7 +12,7 @@ if not sys.platform.startswith("win"):
from fcntl import ioctl from fcntl import ioctl
from scapy.data import * from scapy.data import *
from scapy.config import conf from scapy.config import conf
from scapy.utils import warning from scapy.utils import warning, mac2str
from scapy.supersocket import SuperSocket from scapy.supersocket import SuperSocket
from scapy.error import Scapy_Exception from scapy.error import Scapy_Exception
import scapy.arch import scapy.arch
...@@ -460,12 +460,15 @@ if conf.use_pcap: ...@@ -460,12 +460,15 @@ if conf.use_pcap:
conf.L2listen = L2pcapListenSocket conf.L2listen = L2pcapListenSocket
if conf.use_dnet: if conf.use_dnet:
try: try:
import dnet try:
# First try to import dnet
import dnet
except ImportError:
# Then, try to import dumbnet as dnet
import dumbnet as dnet
except ImportError,e: except ImportError,e:
if conf.interactive: if conf.interactive:
log_loading.error("Unable to import dnet module: %s" % e) log_loading.error("Unable to import dnet module: %s" % e)
...@@ -483,21 +486,41 @@ if conf.use_dnet: ...@@ -483,21 +486,41 @@ if conf.use_dnet:
raise raise
else: else:
def get_if_raw_hwaddr(iff): def get_if_raw_hwaddr(iff):
"""Return a tuple containing the link type and the raw hardware
address corresponding to the interface 'iff'"""
if iff == scapy.arch.LOOPBACK_NAME: if iff == scapy.arch.LOOPBACK_NAME:
return (772, '\x00'*6) return (ARPHDR_LOOPBACK, '\x00'*6)
# Retrieve interface information
try: try:
l = dnet.intf().get(iff) l = dnet.intf().get(iff)
l = l["link_addr"] link_addr = l["link_addr"]
except: except:
raise Scapy_Exception("Error in attempting to get hw address for interface [%s]" % iff) raise Scapy_Exception("Error in attempting to get hw address"
return l.type,l.data " for interface [%s]" % iff)
if hasattr(link_addr, "type"):
# Legacy dnet module
return link_addr.type, link_addr.data
else:
# dumbnet module
mac = mac2str(str(link_addr))
# Adjust the link type
if l["type"] == 6: # INTF_TYPE_ETH from dnet
return (ARPHDR_ETHER, mac)
return (l["type"], mac)
def get_if_raw_addr(ifname): def get_if_raw_addr(ifname):
i = dnet.intf() i = dnet.intf()
return i.get(ifname)["addr"].data return i.get(ifname)["addr"].data
def get_if_list(): def get_if_list():
return [i.get("name", None) for i in dnet.intf()] return [i.get("name", None) for i in dnet.intf()]
if conf.use_pcap and conf.use_dnet: if conf.use_pcap and conf.use_dnet:
class L3dnetSocket(SuperSocket): class L3dnetSocket(SuperSocket):
desc = "read/write packets at layer 3 using libdnet and libpcap" desc = "read/write packets at layer 3 using libdnet and libpcap"
......
...@@ -24,6 +24,20 @@ lsc() ...@@ -24,6 +24,20 @@ lsc()
~ conf ~ conf
conf.debug_dissector = True conf.debug_dissector = True
############
############
+ Scapy functions tests
= Interface related functions
get_if_raw_hwaddr(conf.iface)
get_if_raw_addr(conf.iface).encode("hex")
get_if_list()
############ ############
############ ############
+ Basic tests + Basic tests
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment