X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fresources%2Flinux%2Fscripts%2Ftunchannel.py;h=170bf9d4e23408767cadc5a9e24c5eb153085440;hb=039fbd9629d7570d4c175a5448d24badcd0f3aba;hp=cd30b8b8c9317fb1c9ea6b48211d7ba249b84758;hpb=7f6a711e6d4a245a1f4b104ab9e999af484a8d69;p=nepi.git diff --git a/src/nepi/resources/linux/scripts/tunchannel.py b/src/nepi/resources/linux/scripts/tunchannel.py index cd30b8b8..170bf9d4 100644 --- a/src/nepi/resources/linux/scripts/tunchannel.py +++ b/src/nepi/resources/linux/scripts/tunchannel.py @@ -3,9 +3,8 @@ # Copyright (C) 2013 INRIA # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation; # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -19,6 +18,7 @@ # Claudio Freire # +from __future__ import print_function import select import sys @@ -262,9 +262,9 @@ def tun_fwd(tun, remote, with_pi, ether_mode, cipher_key, udp, TERMINATE, SUSPEN if stderr is not None: if crypto_mode: - print >>stderr, "Packets are transmitted in CIPHER" + print("Packets are transmitted in CIPHER", file=stderr) else: - print >>stderr, "Packets are transmitted in PLAINTEXT" + print("Packets are transmitted in PLAINTEXT", file=stderr) if hasattr(remote, 'fileno'): remote_fd = remote.fileno() @@ -593,13 +593,13 @@ def udp_connect(TERMINATE, local_addr, local_port, peer_addr, peer_port): break except socket.error: # wait a while, retry - print >>sys.stderr, "%s: Could not bind. Retrying in a sec..." % (time.strftime('%c'),) + print("%s: Could not bind. Retrying in a sec..." % (time.strftime('%c'),), file=sys.stderr) time.sleep(min(30.0,retrydelay)) retrydelay *= 1.1 else: rsock.bind((local_addr, local_port)) - print >>sys.stderr, "Listening UDP at: %s:%d" % (local_addr, local_port) - print >>sys.stderr, "Connecting UDP to: %s:%d" % (peer_addr, peer_port) + print("Listening UDP at: %s:%d" % (local_addr, local_port), file=sys.stderr) + print("Connecting UDP to: %s:%d" % (peer_addr, peer_port), file=sys.stderr) rsock.connect((peer_addr, peer_port)) return rsock @@ -655,17 +655,17 @@ def tcp_connect(TERMINATE, stop, rsock, peer_addr, peer_port): break except socket.error: # wait a while, retry - print >>sys.stderr, "%s: Could not connect. Retrying in a sec..." % (time.strftime('%c'),) + print("%s: Could not connect. Retrying in a sec..." % (time.strftime('%c'),), file=sys.stderr) time.sleep(min(30.0,retrydelay)) retrydelay *= 1.1 else: rsock.connect((peer_addr, peer_port)) sock = rsock if sock: - print >>sys.stderr, "tcp_connect: TCP sock connected to remote %s:%s" % (peer_addr, peer_port) + print("tcp_connect: TCP sock connected to remote %s:%s" % (peer_addr, peer_port), file=sys.stderr) sock.settimeout(0) - print >>sys.stderr, "tcp_connect: disabling NAGLE" + print("tcp_connect: disabling NAGLE", file=sys.stderr) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) return sock @@ -684,13 +684,13 @@ def tcp_listen(TERMINATE, stop, lsock, local_addr, local_port): break except socket.error: # wait a while, retry - print >>sys.stderr, "%s: Could not bind. Retrying in a sec..." % (time.strftime('%c'),) + print("%s: Could not bind. Retrying in a sec..." % (time.strftime('%c'),), file=sys.stderr) time.sleep(min(30.0,retrydelay)) retrydelay *= 1.1 else: lsock.bind((local_addr, local_port)) - print >>sys.stderr, "tcp_listen: TCP sock listening in local sock %s:%s" % (local_addr, local_port) + print("tcp_listen: TCP sock listening in local sock %s:%s" % (local_addr, local_port), file=sys.stderr) # Now we wait until the other side connects. # The other side might not be ready yet, so we also wait in a loop for timeouts. timeout = 1 @@ -703,7 +703,7 @@ def tcp_listen(TERMINATE, stop, lsock, local_addr, local_port): break if lsock in rlist: sock,raddr = lsock.accept() - print >>sys.stderr, "tcp_listen: TCP connection accepted in local sock %s:%s" % (local_addr, local_port) + print("tcp_listen: TCP connection accepted in local sock %s:%s" % (local_addr, local_port), file=sys.stderr) break timeout += 5 return sock @@ -718,10 +718,10 @@ def tcp_handshake(rsock, listen, hand): rsock.send(hand) peer_hand = rsock.recv(4) if not peer_hand: - print >>sys.stderr, "tcp_handshake: connection reset by peer" + print("tcp_handshake: connection reset by peer", file=sys.stderr) return False else: - print >>sys.stderr, "tcp_handshake: hand %r, peer_hand %r" % (hand, peer_hand) + print("tcp_handshake: hand %r, peer_hand %r" % (hand, peer_hand), file=sys.stderr) if hand < peer_hand: if listen: win = True @@ -788,5 +788,3 @@ def tcp_establish(TERMINATE, local_addr, local_port, peer_addr, peer_port): if not sock: raise OSError, "Error: tcp_establish could not establish connection." return sock - -