test: reduce further influence from the environment
[metze/wireshark/wip.git] / test / util_dump_dhcp_pcap.py
1 #!/usr/bin/env python
2 #
3 # Wireshark tests
4 # By Gerald Combs <gerald@wireshark.org>
5 #
6 # Ported from a set of Bash scripts which were copyright 2005 Ulf Lamping
7 #
8 # SPDX-License-Identifier: GPL-2.0-or-later
9 #
10 '''Write captures/dhcp.pcap to stdout, optionally writing only packet records or writing them slowly.'''
11
12 import argparse
13 import os
14 import os.path
15 import time
16 import sys
17
18 def main():
19     parser = argparse.ArgumentParser(description='Dump dhcp.pcap')
20     parser.add_argument('dump_type', choices=['cat', 'slow', 'raw'],
21         help='cat: Just dump the file. slow: Dump the file, pause, and dump its packet records. raw: Dump only the packet records.')
22     args = parser.parse_args()
23
24     if sys.version_info[0] < 3 and sys.platform == "win32":
25         import msvcrt
26         msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
27
28     dhcp_pcap = os.path.join(os.path.dirname(__file__), 'captures', 'dhcp.pcap')
29
30     dhcp_fd = open(dhcp_pcap, 'rb')
31     contents = dhcp_fd.read()
32     if args.dump_type != 'raw':
33         os.write(1, contents)
34     if args.dump_type == 'cat':
35         sys.exit(0)
36     if args.dump_type == 'slow':
37         time.sleep(1.5)
38     # slow, raw
39     os.write(1, contents[24:])
40     sys.exit(0)
41
42 if __name__ == '__main__':
43     main()
44