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
8c935c0d
Commit
8c935c0d
authored
9 years ago
by
Pierre LALET
Browse files
Options
Downloads
Patches
Plain Diff
Linux/L2socket: handle .close() to remove promisc mode
parent
15ae22b2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scapy/arch/linux.py
+13
-12
13 additions, 12 deletions
scapy/arch/linux.py
with
13 additions
and
12 deletions
scapy/arch/linux.py
+
13
−
12
View file @
8c935c0d
...
@@ -328,9 +328,7 @@ class L3PacketSocket(SuperSocket):
...
@@ -328,9 +328,7 @@ class L3PacketSocket(SuperSocket):
self
.
ins
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_RCVBUF
,
2
**
30
)
self
.
ins
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_RCVBUF
,
2
**
30
)
self
.
outs
=
socket
.
socket
(
socket
.
AF_PACKET
,
socket
.
SOCK_RAW
,
socket
.
htons
(
type
))
self
.
outs
=
socket
.
socket
(
socket
.
AF_PACKET
,
socket
.
SOCK_RAW
,
socket
.
htons
(
type
))
self
.
outs
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_SNDBUF
,
2
**
30
)
self
.
outs
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_SNDBUF
,
2
**
30
)
if
promisc
is
None
:
self
.
promisc
=
conf
.
promisc
if
promisc
is
None
else
promisc
promisc
=
conf
.
promisc
self
.
promisc
=
promisc
if
self
.
promisc
:
if
self
.
promisc
:
if
iface
is
None
:
if
iface
is
None
:
self
.
iff
=
get_if_list
()
self
.
iff
=
get_if_list
()
...
@@ -344,7 +342,7 @@ class L3PacketSocket(SuperSocket):
...
@@ -344,7 +342,7 @@ class L3PacketSocket(SuperSocket):
def
close
(
self
):
def
close
(
self
):
if
self
.
closed
:
if
self
.
closed
:
return
return
self
.
closed
=
1
self
.
closed
=
1
if
self
.
promisc
:
if
self
.
promisc
:
for
i
in
self
.
iff
:
for
i
in
self
.
iff
:
set_promisc
(
self
.
ins
,
i
,
0
)
set_promisc
(
self
.
ins
,
i
,
0
)
...
@@ -409,8 +407,7 @@ class L3PacketSocket(SuperSocket):
...
@@ -409,8 +407,7 @@ class L3PacketSocket(SuperSocket):
class
L2Socket
(
SuperSocket
):
class
L2Socket
(
SuperSocket
):
desc
=
"
read/write packets at layer 2 using Linux PF_PACKET sockets
"
desc
=
"
read/write packets at layer 2 using Linux PF_PACKET sockets
"
def
__init__
(
self
,
iface
=
None
,
type
=
ETH_P_ALL
,
promisc
=
None
,
filter
=
None
,
nofilter
=
0
):
def
__init__
(
self
,
iface
=
None
,
type
=
ETH_P_ALL
,
promisc
=
None
,
filter
=
None
,
nofilter
=
0
):
if
iface
is
None
:
self
.
iface
=
conf
.
iface
if
iface
is
None
else
iface
iface
=
conf
.
iface
self
.
ins
=
socket
.
socket
(
socket
.
AF_PACKET
,
socket
.
SOCK_RAW
,
socket
.
htons
(
type
))
self
.
ins
=
socket
.
socket
(
socket
.
AF_PACKET
,
socket
.
SOCK_RAW
,
socket
.
htons
(
type
))
self
.
ins
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_RCVBUF
,
0
)
self
.
ins
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_RCVBUF
,
0
)
if
not
nofilter
:
if
not
nofilter
:
...
@@ -421,12 +418,10 @@ class L2Socket(SuperSocket):
...
@@ -421,12 +418,10 @@ class L2Socket(SuperSocket):
filter
=
"
not (%s)
"
%
conf
.
except_filter
filter
=
"
not (%s)
"
%
conf
.
except_filter
if
filter
is
not
None
:
if
filter
is
not
None
:
attach_filter
(
self
.
ins
,
filter
)
attach_filter
(
self
.
ins
,
filter
)
if
promisc
is
None
:
self
.
promisc
=
conf
.
sniff_promisc
if
promisc
is
None
else
promisc
promisc
=
conf
.
sniff_promisc
self
.
promisc
=
promisc
if
self
.
promisc
:
if
self
.
promisc
:
set_promisc
(
self
.
ins
,
iface
)
set_promisc
(
self
.
ins
,
self
.
iface
)
self
.
ins
.
bind
((
iface
,
type
))
self
.
ins
.
bind
((
self
.
iface
,
type
))
_flush_fd
(
self
.
ins
)
_flush_fd
(
self
.
ins
)
self
.
ins
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_RCVBUF
,
2
**
30
)
self
.
ins
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_RCVBUF
,
2
**
30
)
self
.
outs
=
self
.
ins
self
.
outs
=
self
.
ins
...
@@ -439,7 +434,13 @@ class L2Socket(SuperSocket):
...
@@ -439,7 +434,13 @@ class L2Socket(SuperSocket):
else
:
else
:
self
.
LL
=
conf
.
default_l2
self
.
LL
=
conf
.
default_l2
warning
(
"
Unable to guess type (interface=%s protocol=%#x family=%i). Using %s
"
%
(
sa_ll
[
0
],
sa_ll
[
1
],
sa_ll
[
3
],
self
.
LL
.
name
))
warning
(
"
Unable to guess type (interface=%s protocol=%#x family=%i). Using %s
"
%
(
sa_ll
[
0
],
sa_ll
[
1
],
sa_ll
[
3
],
self
.
LL
.
name
))
def
close
(
self
):
if
self
.
closed
:
return
self
.
closed
=
1
if
self
.
promisc
:
set_promisc
(
self
.
ins
,
self
.
iface
,
0
)
SuperSocket
.
close
(
self
)
def
recv
(
self
,
x
=
MTU
):
def
recv
(
self
,
x
=
MTU
):
pkt
,
sa_ll
=
self
.
ins
.
recvfrom
(
x
)
pkt
,
sa_ll
=
self
.
ins
.
recvfrom
(
x
)
if
sa_ll
[
2
]
==
socket
.
PACKET_OUTGOING
:
if
sa_ll
[
2
]
==
socket
.
PACKET_OUTGOING
:
...
...
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