Skip to content

Commit 363d376

Browse files
authored
More consistent sendpfast API (breaking) (#4157)
1 parent 36c074d commit 363d376

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

scapy/sendrecv.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -485,24 +485,25 @@ def sendp(x, # type: _PacketIterable
485485

486486

487487
@conf.commands.register
488-
def sendpfast(x, # type: _PacketIterable
489-
pps=None, # type: Optional[float]
490-
mbps=None, # type: Optional[float]
491-
realtime=False, # type: bool
492-
loop=None, # type: Optional[int]
493-
file_cache=False, # type: bool
494-
iface=None, # type: Optional[_GlobInterfaceType]
495-
replay_args=None, # type: Optional[List[str]]
496-
parse_results=False, # type: bool
488+
def sendpfast(x: _PacketIterable,
489+
pps: Optional[float] = None,
490+
mbps: Optional[float] = None,
491+
realtime: bool = False,
492+
count: Optional[int] = None,
493+
loop: int = 0,
494+
file_cache: bool = False,
495+
iface: Optional[_GlobInterfaceType] = None,
496+
replay_args: Optional[List[str]] = None,
497+
parse_results: bool = False,
497498
):
498499
# type: (...) -> Optional[Dict[str, Any]]
499500
"""Send packets at layer 2 using tcpreplay for performance
500501
501502
:param pps: packets per second
502503
:param mbps: MBits per second
503504
:param realtime: use packet's timestamp, bending time with real-time value
504-
:param loop: number of times to process the packet list. 0 implies
505-
infinite loop
505+
:param loop: send the packet indefinitely (default 0)
506+
:param count: number of packets to send (default None=1)
506507
:param file_cache: cache packets in RAM instead of reading from
507508
disk at each iteration
508509
:param iface: output interface
@@ -523,8 +524,11 @@ def sendpfast(x, # type: _PacketIterable
523524
else:
524525
argv.append("--topspeed")
525526

526-
if loop is not None:
527-
argv.append("--loop=%i" % loop)
527+
if count:
528+
assert not loop, "Can't use loop and count at the same time in sendpfast"
529+
argv.append("--loop=%i" % count)
530+
elif loop:
531+
argv.append("--loop=0")
528532
if file_cache:
529533
argv.append("--preload-pcap")
530534

scapy/supersocket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def close(self):
214214
def sr(self, *args, **kargs):
215215
# type: (Any, Any) -> Tuple[SndRcvList, PacketList]
216216
from scapy import sendrecv
217-
ans, unans = sendrecv.sndrcv(self, *args, **kargs) # type: SndRcvList, PacketList # noqa: E501
217+
ans, unans = sendrecv.sndrcv(self, *args, **kargs)
218218
return ans, unans
219219

220220
def sr1(self, *args, **kargs):

0 commit comments

Comments
 (0)