]>
Commit | Line | Data |
---|---|---|
7aa697dd BP |
1 | #! @PYTHON@ |
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 | ||
23 | def usage(): | |
24 | print """\ | |
25 | %(argv0)s: print "tcpdump -xx" output as hex | |
26 | usage: %(argv0)s < FILE | |
27 | where FILE is output from "tcpdump -xx". | |
28 | ||
29 | The following options are also available: | |
30 | -h, --help display this help message | |
31 | -V, --version display version information\ | |
32 | """ % {'argv0': argv0} | |
33 | sys.exit(0) | |
34 | ||
35 | if __name__ == "__main__": | |
36 | try: | |
37 | options, args = getopt.gnu_getopt(sys.argv[1:], 'hV', | |
38 | ['help', 'version']) | |
a4c1a933 | 39 | except getopt.GetoptError, geo: |
7aa697dd BP |
40 | sys.stderr.write("%s: %s\n" % (argv0, geo.msg)) |
41 | sys.exit(1) | |
42 | ||
43 | for key, value in options: | |
44 | if key in ['-h', '--help']: | |
45 | usage() | |
46 | elif key in ['-V', '--version']: | |
47 | print "ovs-pcap (Open vSwitch) @VERSION@" | |
48 | else: | |
49 | sys.exit(0) | |
50 | ||
51 | if len(args) != 0: | |
52 | sys.stderr.write("%s: non-option argument not supported " | |
53 | "(use --help for help)\n" % argv0) | |
54 | sys.exit(1) | |
55 | ||
56 | packet = '' | |
57 | regex = re.compile(r'^\s+0x([0-9a-fA-F]+): ((?: [0-9a-fA-F]{4})+)') | |
58 | while True: | |
59 | line = sys.stdin.readline() | |
60 | if line == "": | |
61 | break | |
62 | ||
63 | m = regex.match(line) | |
64 | if m is None or int(m.group(1)) == 0: | |
65 | if packet != '': | |
66 | print packet | |
67 | packet = '' | |
68 | if m: | |
69 | packet += re.sub(r'\s', '', m.group(2), 0) | |
70 | if packet != '': | |
71 | print packet | |
72 | ||
73 | # Local variables: | |
74 | # mode: python | |
75 | # End: |