From 8204a1b694ae945d24b88b46edf74b29eb0022e6 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Wed, 13 Mar 2013 16:16:20 -0700 Subject: [PATCH] fix --ipbase: fix ipAdd() and remove unused default from ipStr() --- mininet/util.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mininet/util.py b/mininet/util.py index 2461210..8ae96b5 100644 --- a/mininet/util.py +++ b/mininet/util.py @@ -242,9 +242,8 @@ def macColonHex( mac ): def ipStr( ip ): """Generate IP address string from an unsigned int. ip: unsigned int of form w << 24 | x << 16 | y << 8 | z - returns: ip address string w.x.y.z, or 10.x.y.z if w==0""" + returns: ip address string w.x.y.z""" w = ( ip >> 24 ) & 0xff - w = 10 if w == 0 else w x = ( ip >> 16 ) & 0xff y = ( ip >> 8 ) & 0xff z = ip & 0xff @@ -261,10 +260,10 @@ def ipAdd( i, prefixLen=8, ipBaseNum=0x0a000000 ): prefixLen: optional IP prefix length ipBaseNum: option base IP address as int returns IP address as string""" - # Ugly but functional - assert i < ( 1 << ( 32 - prefixLen ) ) - mask = 0xffffffff ^ ( ( 1 << prefixLen ) - 1 ) - ipnum = i + ( ipBaseNum & mask ) + imax = 0xffffffff >> prefixLen + assert i <= imax + mask = 0xffffffff ^ imax + ipnum = ( ipBaseNum & mask ) + i return ipStr( ipnum ) def ipParse( ip ):