import time
def ipfmt(ip):
- ipbytes = map(ord,ip.decode("hex"))
- return '.'.join(map(str,ipbytes))
+ return '.'.join(str(ord(x)) for x in ip.decode("hex"))
tagtype = {
'0806' : 'arp',
buf,
))
-_padmap = [ chr(padding) * padding for padding in xrange(127) ]
+_padmap = [ chr(padding) * padding for padding in range(127) ]
del padding
def encrypt(packet, crypter, len=len, padmap=_padmap):
sent = 0
try:
try:
- for x in xrange(maxbatch):
+ for x in range(maxbatch):
packet = pullPacket(fwbuf)
if crypto_mode:
bwfree -= sent
if tun in wrdy:
try:
- for x in xrange(maxtbatch):
+ for x in range(maxtbatch):
packet = pullPacket(bkbuf)
twrite(tunfd, packet)
#wt += 1
# check incoming data packets
if tun in rdrdy:
try:
- for x in xrange(maxbatch):
+ for x in range(maxbatch):
packet = tread(tunfd,2000) # tun.read blocks until it gets 2k!
if not packet:
continue
if remote in rdrdy:
try:
try:
- for x in xrange(maxbatch):
+ for x in range(maxbatch):
packet = rread(remote,2000)
#rr += 1
def udp_connect(TERMINATE, local_addr, local_port, peer_addr, peer_port):
rsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
retrydelay = 1.0
- for i in xrange(30):
+ for i in range(30):
# TERMINATE is a array. An item can be added to TERMINATE, from
# outside this function to force termination of the loop
if TERMINATE:
pass
keepalive_thread = threading.Thread(target=keepalive)
keepalive_thread.start()
- for i in xrange(900):
+ for i in range(900):
if TERMINATE:
raise OSError("Killed")
try:
# will be forever blocked in the connect, so we put a reasonable timeout.
rsock.settimeout(10)
# We wait for
- for i in xrange(30):
+ for i in range(30):
if stop:
break
if TERMINATE:
retrydelay = 1.0
# We try to bind to the local virtual interface.
# It might not exist yet so we wait in a loop.
- for i in xrange(30):
+ for i in range(30):
if stop:
break
if TERMINATE:
# The other side might not be ready yet, so we also wait in a loop for timeouts.
timeout = 1
lsock.listen(1)
- for i in xrange(30):
+ for i in range(30):
if TERMINATE:
raise OSError("Killed")
rlist, wlist, xlist = select.select([lsock], [], [], timeout)
end = False
sock = None
- for i in xrange(0, 50):
+ for i in range(0, 50):
if end:
break
if TERMINATE: