From 8fbd46f287e996cc772c1d1f73310dda730b4ea6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20De=20Keersmaeker?=
 <francois.dekeersmaeker@uclouvain.be>
Date: Fri, 12 Jul 2024 17:09:19 +0200
Subject: [PATCH] Argument output is now optional and defaults to None

---
 README.md                  | 2 +-
 pcap_fuzzer/pcap_fuzzer.py | 5 ++---
 setup.py                   | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 43bb09a..de5311f 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ import pcap_fuzzer
 ```python
 pcap_fuzzer.fuzz_pcaps(
     pcaps: Union[str, list]       # (List of) input PCAP files
-    output: str,                  # Output PCAP file path. Used only if a single input file is specified.
+    output: str,                  # [Optional] Output PCAP file path. Used only if a single input file is specified.
     random_range: int = 1,        # [Optional] Upper bound for random range (not included). Defaults to 1.
     packet_numbers: list = None,  # [Optional] List of indices, starting from 1, of packets to edit. If not specified, packets are randomly picked.
     dry_run: bool = False         # [Optional] If True, do not write output PCAP file(s).
diff --git a/pcap_fuzzer/pcap_fuzzer.py b/pcap_fuzzer/pcap_fuzzer.py
index 8430e15..5edbe1e 100644
--- a/pcap_fuzzer/pcap_fuzzer.py
+++ b/pcap_fuzzer/pcap_fuzzer.py
@@ -49,7 +49,7 @@ def must_edit_packet(i: int, packet_numbers: list, random_range: int) -> bool:
     return is_specified or is_random
 
 
-def fuzz_pcaps(pcaps: Union[str, list], output: str, random_range: int = 1, packet_numbers: list = None, dry_run: bool = False) -> None:
+def fuzz_pcaps(pcaps: Union[str, list], output: str = None, random_range: int = 1, packet_numbers: list = None, dry_run: bool = False) -> None:
     """
     Main functionality of the program:
     (Randomly) edit packet fields in a (list of) PCAP file(s).
@@ -117,7 +117,6 @@ def fuzz_pcaps(pcaps: Union[str, list], output: str, random_range: int = 1, pack
                 i += 1
 
         # Write output PCAP file
-        output_pcap = ""
         if output is not None and len(pcaps) == 1:
             output_pcap = output
         else:
@@ -150,7 +149,7 @@ if __name__ == "__main__":
     # Positional arguments: input PCAP file(s)
     parser.add_argument("input_pcaps", metavar="pcap", type=str, nargs="+", help="Input PCAP file(s).")
     # Optional flag: -o / --output
-    parser.add_argument("-o", "--output", type=str, help="Output PCAP (and CSV) file path. Used only if a single input file is specified. Default: edited/<input_pcap>.edit.pcap")
+    parser.add_argument("-o", "--output", type=str, default=None, help="Output PCAP (and CSV) file path. Used only if a single input file is specified. Default: edited/<input_pcap>.edit.pcap")
     # Optional flag: -r / --random-range
     parser.add_argument("-r", "--random-range", type=strictly_positive_int, default=1,
                         help="Upper bound for random range (not included). Must be a strictly positive integer. Default: 1 (edit each packet).")
diff --git a/setup.py b/setup.py
index 50023af..a088a00 100644
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
 
 setup(
     name='pcap_fuzzer',
-    version='0.3.0',
+    version='0.4.0',
     author='François De Keersmaeker',
     author_email='francois.dekeersmaeker@uclouvain.be',
     description='Randomly edit packet fields in a PCAP file.',
-- 
GitLab