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
767de935
Commit
767de935
authored
8 years ago
by
Pierre LALET
Browse files
Options
Downloads
Patches
Plain Diff
Fix tcpdump with MacOS (-r - won't work, @guedou @gpotter2)
parent
598bdae8
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/utils.py
+42
-12
42 additions, 12 deletions
scapy/utils.py
with
42 additions
and
12 deletions
scapy/utils.py
+
42
−
12
View file @
767de935
...
...
@@ -12,6 +12,7 @@ import random,time
import
gzip
,
zlib
,
cPickle
import
re
,
struct
,
array
import
subprocess
import
tempfile
import
warnings
warnings
.
filterwarnings
(
"
ignore
"
,
"
tempnam
"
,
RuntimeWarning
,
__name__
)
...
...
@@ -1139,19 +1140,48 @@ To get a JSON representation of a tshark-parsed PacketList(), one can:
u
'
64
'
"""
proc
=
subprocess
.
Popen
(
[
conf
.
prog
.
tcpdump
if
prog
is
None
else
prog
,
"
-r
"
,
pktlist
if
isinstance
(
pktlist
,
basestring
)
else
"
-
"
]
+
([
"
-n
"
]
if
args
is
None
else
args
),
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
if
dump
or
getfd
else
None
,
)
try
:
proc
.
stdin
.
writelines
(
iter
(
lambda
:
pktlist
.
read
(
1048576
),
""
))
except
AttributeError
:
wrpcap
(
proc
.
stdin
,
pktlist
)
if
isinstance
(
pktlist
,
basestring
):
proc
=
subprocess
.
Popen
(
[
conf
.
prog
.
tcpdump
if
prog
is
None
else
prog
,
"
-r
"
,
pktlist
]
+
([
"
-n
"
]
if
args
is
None
else
args
),
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
if
dump
or
getfd
else
None
,
stderr
=
open
(
os
.
devnull
),
)
elif
sys
.
platform
.
startswith
(
"
darwin
"
):
# Tcpdump cannot read from stdin, see
# <http://apple.stackexchange.com/questions/152682/>
tmpfile
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
)
try
:
tmpfile
.
writelines
(
iter
(
lambda
:
pktlist
.
read
(
1048576
),
""
))
except
AttributeError
:
wrpcap
(
tmpfile
,
pktlist
)
else
:
tmpfile
.
close
()
proc
=
subprocess
.
Popen
(
[
conf
.
prog
.
tcpdump
if
prog
is
None
else
prog
,
"
-r
"
,
tmpfile
.
name
]
+
([
"
-n
"
]
if
args
is
None
else
args
),
stdout
=
subprocess
.
PIPE
if
dump
or
getfd
else
None
,
stderr
=
open
(
os
.
devnull
),
)
def
newdel
(
self
,
*
args
,
**
kargs
):
os
.
unlink
(
tmpfile
.
name
)
proc
.
__del__
(
self
,
*
args
,
**
kargs
)
proc
.
__del__
=
newdel
else
:
proc
.
stdin
.
close
()
proc
=
subprocess
.
Popen
(
[
conf
.
prog
.
tcpdump
if
prog
is
None
else
prog
,
"
-r
"
,
"
-
"
]
+
([
"
-n
"
]
if
args
is
None
else
args
),
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
if
dump
or
getfd
else
None
,
stderr
=
open
(
os
.
devnull
),
)
try
:
proc
.
stdin
.
writelines
(
iter
(
lambda
:
pktlist
.
read
(
1048576
),
""
))
except
AttributeError
:
wrpcap
(
proc
.
stdin
,
pktlist
)
else
:
proc
.
stdin
.
close
()
if
dump
:
return
""
.
join
(
iter
(
lambda
:
proc
.
stdout
.
read
(
1048576
),
""
))
if
getfd
:
...
...
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