]>
Commit | Line | Data |
---|---|---|
1ca0323e | 1 | #! @PYTHON3@ |
7aa697dd | 2 | # |
e0edde6f | 3 | # Copyright (c) 2010 Nicira, Inc. |
7aa697dd BP |
4 | # |
5 | # Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | # you may not use this file except in compliance with the License. | |
7 | # You may obtain a copy of the License at: | |
8 | # | |
9 | # http://www.apache.org/licenses/LICENSE-2.0 | |
10 | # | |
11 | # Unless required by applicable law or agreed to in writing, software | |
12 | # distributed under the License is distributed on an "AS IS" BASIS, | |
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | # See the License for the specific language governing permissions and | |
15 | # limitations under the License. | |
16 | ||
17 | import getopt | |
18 | import re | |
19 | import sys | |
20 | ||
21 | argv0 = sys.argv[0] | |
22 | ||
227abb77 | 23 | |
7aa697dd | 24 | def usage(): |
227abb77 | 25 | print("""\ |
7aa697dd BP |
26 | %(argv0)s: print "tcpdump -xx" output as hex |
27 | usage: %(argv0)s < FILE | |
28 | where FILE is output from "tcpdump -xx". | |
29 | ||
30 | The following options are also available: | |
31 | -h, --help display this help message | |
32 | -V, --version display version information\ | |
227abb77 | 33 | """ % {'argv0': argv0}) |
7aa697dd BP |
34 | sys.exit(0) |
35 | ||
227abb77 | 36 | |
7aa697dd BP |
37 | if __name__ == "__main__": |
38 | try: | |
39 | options, args = getopt.gnu_getopt(sys.argv[1:], 'hV', | |
40 | ['help', 'version']) | |
227abb77 | 41 | except getopt.GetoptError as geo: |
7aa697dd BP |
42 | sys.stderr.write("%s: %s\n" % (argv0, geo.msg)) |
43 | sys.exit(1) | |
44 | ||
45 | for key, value in options: | |
46 | if key in ['-h', '--help']: | |
47 | usage() | |
48 | elif key in ['-V', '--version']: | |
227abb77 | 49 | print("ovs-tcpundump (Open vSwitch) @VERSION@") |
c691cffb | 50 | sys.exit(0) |
7aa697dd BP |
51 | else: |
52 | sys.exit(0) | |
53 | ||
54 | if len(args) != 0: | |
55 | sys.stderr.write("%s: non-option argument not supported " | |
56 | "(use --help for help)\n" % argv0) | |
57 | sys.exit(1) | |
58 | ||
59 | packet = '' | |
1051576c | 60 | regex = re.compile(r'^\s+0x([0-9a-fA-F]+): ((?: [0-9a-fA-F]{2,4})+)') |
7aa697dd BP |
61 | while True: |
62 | line = sys.stdin.readline() | |
63 | if line == "": | |
64 | break | |
65 | ||
66 | m = regex.match(line) | |
cb12f42d | 67 | if m is None or int(m.group(1), 16) == 0: |
7aa697dd | 68 | if packet != '': |
227abb77 | 69 | print(packet) |
7aa697dd BP |
70 | packet = '' |
71 | if m: | |
72 | packet += re.sub(r'\s', '', m.group(2), 0) | |
73 | if packet != '': | |
227abb77 | 74 | print(packet) |
7aa697dd BP |
75 | |
76 | # Local variables: | |
77 | # mode: python | |
78 | # End: |