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
84fa27ac
Commit
84fa27ac
authored
7 years ago
by
Pierre LALET
Browse files
Options
Downloads
Patches
Plain Diff
sndrcv(): fix timeout handling
parent
87073693
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scapy/sendrecv.py
+9
-12
9 additions, 12 deletions
scapy/sendrecv.py
with
9 additions
and
12 deletions
scapy/sendrecv.py
+
9
−
12
View file @
84fa27ac
...
@@ -67,14 +67,15 @@ def _sndrcv_snd(pks, timeout, inter, verbose, tobesent, all_stimuli, stopevent):
...
@@ -67,14 +67,15 @@ def _sndrcv_snd(pks, timeout, inter, verbose, tobesent, all_stimuli, stopevent):
log_runtime
.
info
(
"
--- Error sending packets
"
)
log_runtime
.
info
(
"
--- Error sending packets
"
)
if
timeout
is
not
None
:
if
timeout
is
not
None
:
stopevent
.
wait
(
timeout
)
stopevent
.
wait
(
timeout
)
pks
.
clo
se
()
stopevent
.
se
t
()
def
sndrcv
(
pks
,
pkt
,
timeout
=
None
,
inter
=
0
,
verbose
=
None
,
chainCC
=
False
,
def
sndrcv
(
pks
,
pkt
,
timeout
=
None
,
inter
=
0
,
verbose
=
None
,
chainCC
=
False
,
retry
=
0
,
multi
=
False
):
retry
=
0
,
multi
=
False
):
if
conf
.
use_bpf
:
from
scapy.arch.bpf.supersocket
import
bpf_select
if
not
isinstance
(
pkt
,
Gen
):
if
not
isinstance
(
pkt
,
Gen
):
pkt
=
SetGen
(
pkt
)
pkt
=
SetGen
(
pkt
)
if
verbose
is
None
:
if
verbose
is
None
:
verbose
=
conf
.
verb
verbose
=
conf
.
verb
debug
.
recv
=
plist
.
PacketList
([],
"
Unanswered
"
)
debug
.
recv
=
plist
.
PacketList
([],
"
Unanswered
"
)
...
@@ -108,25 +109,20 @@ def sndrcv(pks, pkt, timeout=None, inter=0, verbose=None, chainCC=False,
...
@@ -108,25 +109,20 @@ def sndrcv(pks, pkt, timeout=None, inter=0, verbose=None, chainCC=False,
stopevent
),
stopevent
),
)
)
thread
.
start
()
thread
.
start
()
stoptime
=
0
remaintime
=
None
try
:
try
:
try
:
try
:
while
True
:
while
True
:
if
stoptime
:
remaintime
=
stoptime
-
time
.
time
()
if
remaintime
<=
0
:
break
r
=
None
r
=
None
if
WINDOWS
:
if
WINDOWS
:
r
=
pks
.
recv
(
MTU
)
r
=
pks
.
recv
(
MTU
)
elif
conf
.
use_bpf
:
elif
conf
.
use_bpf
:
from
scapy.arch.bpf.supersocket
import
bpf_select
inp
=
bpf_select
([
pks
])
inp
=
bpf_select
([
pks
])
if
pks
in
inp
:
if
pks
in
inp
:
r
=
pks
.
recv
()
r
=
pks
.
recv
()
elif
conf
.
use_pcap
:
elif
conf
.
use_pcap
:
r
=
pks
.
nonblock_recv
()
r
=
pks
.
nonblock_recv
()
if
r
is
None
:
time
.
sleep
(
0.05
)
elif
not
isinstance
(
pks
,
StreamSocket
)
and
(
elif
not
isinstance
(
pks
,
StreamSocket
)
and
(
FREEBSD
or
DARWIN
or
OPENBSD
FREEBSD
or
DARWIN
or
OPENBSD
):
):
...
@@ -136,17 +132,17 @@ def sndrcv(pks, pkt, timeout=None, inter=0, verbose=None, chainCC=False,
...
@@ -136,17 +132,17 @@ def sndrcv(pks, pkt, timeout=None, inter=0, verbose=None, chainCC=False,
else
:
else
:
inp
=
[]
inp
=
[]
try
:
try
:
inp
,
_
,
_
=
select
([
pks
],
[],
[],
remaintime
)
inp
,
_
,
_
=
select
([
pks
],
[],
[],
0.05
)
except
(
IOError
,
select_error
)
as
exc
:
except
(
IOError
,
select_error
)
as
exc
:
# select.error has no .errno attribute
# select.error has no .errno attribute
if
exc
.
args
[
0
]
!=
errno
.
EINTR
:
if
exc
.
args
[
0
]
!=
errno
.
EINTR
:
raise
raise
if
len
(
inp
)
==
0
:
if
not
inp
and
stopevent
.
is_set
()
:
break
break
if
pks
in
inp
:
if
pks
in
inp
:
r
=
pks
.
recv
(
MTU
)
r
=
pks
.
recv
(
MTU
)
if
r
is
None
:
if
r
is
None
:
if
pks
.
closed
:
if
stopevent
.
is_set
()
:
break
break
continue
continue
ok
=
0
ok
=
0
...
@@ -181,6 +177,7 @@ def sndrcv(pks, pkt, timeout=None, inter=0, verbose=None, chainCC=False,
...
@@ -181,6 +177,7 @@ def sndrcv(pks, pkt, timeout=None, inter=0, verbose=None, chainCC=False,
finally
:
finally
:
stopevent
.
set
()
stopevent
.
set
()
thread
.
join
()
thread
.
join
()
pks
.
close
()
remain
=
list
(
itertools
.
chain
(
*
six
.
itervalues
(
hsent
)))
remain
=
list
(
itertools
.
chain
(
*
six
.
itervalues
(
hsent
)))
if
multi
:
if
multi
:
...
...
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