Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions scapy/sendrecv.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ def sendpfast(x: _PacketIterable,
argv.append(f)
wrpcap(f, x)
results = None
cmd = None
with ContextManagerSubprocess(conf.prog.tcpreplay):
try:
cmd = subprocess.Popen(argv, stdout=subprocess.PIPE,
Expand All @@ -593,13 +594,14 @@ def sendpfast(x: _PacketIterable,
os.unlink(f)
raise
finally:
stdout, stderr = cmd.communicate()
if stderr:
log_runtime.warning(stderr.decode())
if parse_results:
results = _parse_tcpreplay_result(stdout, stderr, argv)
elif conf.verb > 2:
log_runtime.info(stdout.decode())
if cmd is not None:
stdout, stderr = cmd.communicate()
if stderr:
log_runtime.warning(stderr.decode())
if parse_results:
results = _parse_tcpreplay_result(stdout, stderr, argv)
elif conf.verb > 2:
log_runtime.info(stdout.decode())
if os.path.exists(f):
os.unlink(f)
return results
Expand Down
12 changes: 12 additions & 0 deletions test/regression.uts
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,18 @@ except Exception:
conf.interactive = old_interactive
assert True

= sendpfast - tcpreplay not installed
* A missing tcpreplay must be reported as such, not hidden by an UnboundLocalError

old_tcpreplay = conf.prog.tcpreplay
conf.prog.tcpreplay = "/nonexistent/tcpreplay"
try:
with mock.patch("scapy.utils.log_runtime.error") as log_error:
assert sendpfast(Ether() / IP()) is None
assert "is it installed?" in log_error.call_args[0][0]
finally:
conf.prog.tcpreplay = old_tcpreplay

############
############
+ Generator tests
Expand Down
Loading