aboutsummaryrefslogtreecommitdiffstats
path: root/test/util_dump_dhcp_pcap.py
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2018-04-27 10:35:17 -0700
committerGerald Combs <gerald@wireshark.org>2018-04-27 19:52:04 +0000
commite6d129bf2382b9f0261c813c5b501db8911b254b (patch)
tree46d23bb44ca6621efbabb2ada0c65854b2d68b6a /test/util_dump_dhcp_pcap.py
parent9b3be1711f2a92ed4c59e32961d4d19b8f593d94 (diff)
Test: Add fileformats and I/O.
Add the fileformats and I/O suites. Move some more common code to subprocesstest.py and add a diffOutput method. Change-Id: I2ec34e46539022bdce78520645fdca6dfc1a8c1a Reviewed-on: https://code.wireshark.org/review/27183 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'test/util_dump_dhcp_pcap.py')
-rwxr-xr-xtest/util_dump_dhcp_pcap.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/util_dump_dhcp_pcap.py b/test/util_dump_dhcp_pcap.py
new file mode 100755
index 0000000000..2fbd7fa138
--- /dev/null
+++ b/test/util_dump_dhcp_pcap.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+#
+# Wireshark tests
+# By Gerald Combs <gerald@wireshark.org>
+#
+# Ported from a set of Bash scripts which were copyright 2005 Ulf Lamping
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+'''Write captures/dhcp.pcap to stdout, optionally writing only packet records or writing them slowly.'''
+
+import argparse
+import os
+import os.path
+import time
+import sys
+
+def main():
+ parser = argparse.ArgumentParser(description='Dump dhcp.pcap')
+ parser.add_argument('dump_type', choices=['cat', 'slow', 'raw'],
+ help='cat: Just dump the file. slow: Dump the file, pause, and dump its packet records. raw: Dump only the packet records.')
+ args = parser.parse_args()
+
+ if sys.version_info[0] < 3 and sys.platform == "win32":
+ import msvcrt
+ msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
+
+ dhcp_pcap = os.path.join(os.path.dirname(__file__), 'captures', 'dhcp.pcap')
+
+ dhcp_fd = open(dhcp_pcap, 'rb')
+ contents = dhcp_fd.read()
+ if args.dump_type != 'raw':
+ os.write(1, contents)
+ if args.dump_type == 'cat':
+ sys.exit(0)
+ if args.dump_type == 'slow':
+ time.sleep(1.5)
+ # slow, raw
+ os.write(1, contents[24:])
+ sys.exit(0)
+
+if __name__ == '__main__':
+ main()
+