From faf13ff99fd47424c4fb93f1c2a6b3b80c81e0d1 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 23 Jul 2013 12:54:09 +0900 Subject: addrconv: replace bin<->text converters for ipv6 Signed-off-by: YAMAMOTO Takashi Signed-off-by: FUJITA Tomonori --- ryu/lib/ip.py | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/ryu/lib/ip.py b/ryu/lib/ip.py index b302d8d8..7b2e29dd 100644 --- a/ryu/lib/ip.py +++ b/ryu/lib/ip.py @@ -1,4 +1,4 @@ -import struct +from ryu.lib import addrconv def ipv4_arg_to_bin(w, x, y, z): @@ -26,39 +26,16 @@ def ipv4_to_str(ip): z = ip & 0xff return "%i.%i.%i.%i" % (w, x, y, z) -IPV6_PACK_STR = '!8H' - - -def ipv6_to_arg_list(ipv6): - ''' - convert ipv6 string to a list of 8 different parts - ''' - args = [] - if '::' in ipv6: - h, t = ipv6.split('::') - h_list = [int(x, 16) for x in h.split(':')] - t_list = [int(x, 16) for x in t.split(':')] - args += h_list - zero = [0] - args += ((8 - len(h_list) - len(t_list)) * zero) - args += t_list - else: - args = [int(x, 16) for x in ipv6.split(':')] - - return args - def ipv6_to_bin(ipv6): ''' convert ipv6 string to binary representation ''' - args = ipv6_to_arg_list(ipv6) - return struct.pack(IPV6_PACK_STR, *args) + return addrconv.ipv6.text_to_bin(ipv6) def ipv6_to_str(bin_addr): ''' convert binary representation to human readable string ''' - args = struct.unpack_from(IPV6_PACK_STR, bin_addr) - return ':'.join('%x' % x for x in args) + return addrconv.ipv6.bin_to_text(bin_addr) -- cgit v1.2.3