Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
2ec520aa
Commit
2ec520aa
authored
8 years ago
by
Guillaume Valadon
Committed by
Pierre Lalet
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Scapy can now use dumbnet
parent
5a5bea6a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scapy/arch/pcapdnet.py
+33
-10
33 additions, 10 deletions
scapy/arch/pcapdnet.py
test/regression.uts
+14
-0
14 additions, 0 deletions
test/regression.uts
with
47 additions
and
10 deletions
scapy/arch/pcapdnet.py
+
33
−
10
View file @
2ec520aa
...
@@ -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
"
]
l
ink_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
"
...
...
This diff is collapsed.
Click to expand it.
test/regression.uts
+
14
−
0
View file @
2ec520aa
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment