From 2176423b4ab5ddb5b23d9bfd1417c7280b3f5129 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 16 Oct 2016 11:59:32 +0200 Subject: extcap_example.py: fixes for Python 3 Fixes trivial syntax error in try/except, ensure that the message are bytes instead of a string and remove unnecessary use of an append_bytes function. Did not try to fix the other Python issues, at least it runs now. Change-Id: Ib24f6116bc9d3cf177bc940da9f89aff90695a93 Reviewed-on: https://code.wireshark.org/review/18212 Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu --- doc/extcap_example.py | 69 ++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 37 deletions(-) (limited to 'doc/extcap_example.py') diff --git a/doc/extcap_example.py b/doc/extcap_example.py index 02a3f2b8c5..de28da01af 100755 --- a/doc/extcap_example.py +++ b/doc/extcap_example.py @@ -147,21 +147,16 @@ Extcap capture routine def unsigned(n): return int(n) & 0xFFFFFFFF -def append_bytes(ba, blist): - for c in range(0, len(blist)): - ba.append(blist[c]) - return ba - def pcap_fake_header(): header = bytearray() - header = append_bytes(header, struct.pack('H', unsigned(len(message)+20) )) # length of data + payload - pcap = append_bytes(pcap, struct.pack('H', unsigned(len(message)+20) ) # length of data + payload + pcap += struct.pack('L', ipadr )) # Source IP - pcap = append_bytes(pcap, struct.pack('>L', int ( '7F000001', 16) )) # Dest IP + pcap += struct.pack('>L', ipadr ) # Source IP + pcap += struct.pack('>L', int ( '7F000001', 16 )) # Dest IP - pcap = append_bytes(pcap, message) + pcap += message return pcap def extcap_capture(interface, fifo, delay, verify, message, remote, fake_ip): @@ -234,7 +229,7 @@ def extcap_capture(interface, fifo, delay, verify, message, remote, fake_ip): fh.write (pcap_fake_header()) while doExit == False: - out = str( "%s|%04X%s|%s" % ( remote.strip(), len(message), message, verify ) ) + out = ("%s|%04X%s|%s" % ( remote.strip(), len(message), message, verify )).encode("utf8") try: fh.write (pcap_fake_package(out, fake_ip)) time.sleep(tdelay) @@ -296,7 +291,7 @@ if __name__ == '__main__': try: args, unknown = parser.parse_known_args() - except argparse.ArgumentError, exc: + except argparse.ArgumentError as exc: print( "%s: %s" % ( exc.argument.dest, exc.message ), file=sys.stderr) fifo_found = 0 fifo = "" -- cgit v1.2.3