From c0f410822cc1d303f1c4993799a9a7530719337b Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Wed, 25 Jul 2012 17:16:50 -0400 Subject: [PATCH] support for reading and writing ipv6 addresses --- p2pool/util/pack.py | 17 ++++++++++------- 1 files changed, 10 insertions(+), 7 deletions(-) diff --git a/p2pool/util/pack.py b/p2pool/util/pack.py index d96f1e9..d097aef 100644 --- a/p2pool/util/pack.py +++ b/p2pool/util/pack.py @@ -209,15 +209,18 @@ class IntType(Type): class IPV6AddressType(Type): def read(self, file): data, file = read(file, 16) - if data[:12] != '00000000000000000000ffff'.decode('hex'): - raise ValueError('ipv6 addresses not supported yet') - return '.'.join(str(ord(x)) for x in data[12:]), file + if data[:12] == '00000000000000000000ffff'.decode('hex'): + return '.'.join(str(ord(x)) for x in data[12:]), file + return ':'.join(data[i*2:(i+1)*2].encode('hex') for i in xrange(8)), file def write(self, file, item): - bits = map(int, item.split('.')) - if len(bits) != 4: - raise ValueError('invalid address: %r' % (bits,)) - data = '00000000000000000000ffff'.decode('hex') + ''.join(chr(x) for x in bits) + if ':' in item: + data = ''.join(item.replace(':', '')).decode('hex') + else: + bits = map(int, item.split('.')) + if len(bits) != 4: + raise ValueError('invalid address: %r' % (bits,)) + data = '00000000000000000000ffff'.decode('hex') + ''.join(chr(x) for x in bits) assert len(data) == 16, len(data) return file, data -- 1.7.1