summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorharro@google.com <harro@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035>2010-10-06 04:20:57 +0000
committerharro@google.com <harro@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035>2010-10-06 04:20:57 +0000
commit352f0cee221a0537cb1334996a1a6d364d3f759a (patch)
tree304857f9c8fa806f463075d213dc49b3ed0a6843
parente6caed5c520669e7dc5e588523aa6959ba5ff340 (diff)
downloadipaddr-py-352f0cee221a0537cb1334996a1a6d364d3f759a.tar.gz
IPv6 with embedded IPv4 address not recognized
git-svn-id: https://ipaddr-py.googlecode.com/svn@194 09200d28-7f98-11dd-ad27-0f66e57d2035
-rw-r--r--trunk/ipaddr.py5
-rwxr-xr-xtrunk/ipaddr_test.py9
2 files changed, 12 insertions, 2 deletions
diff --git a/trunk/ipaddr.py b/trunk/ipaddr.py
index 16e0a4d..4c02378 100644
--- a/trunk/ipaddr.py
+++ b/trunk/ipaddr.py
@@ -1394,10 +1394,9 @@ class _BaseV6(object):
ip_int = 0
- fields = self._explode_shorthand_ip_string(ip_str).split(':')
-
# Do we have an IPv4 mapped (::ffff:a.b.c.d) or compact (::a.b.c.d)
# ip_str?
+ fields = ip_str.split(':')
if fields[-1].count('.') == 3:
ipv4_string = fields.pop()
ipv4_int = IPv4Network(ipv4_string)._ip
@@ -1406,7 +1405,9 @@ class _BaseV6(object):
octets.append(hex(ipv4_int & 0xFFFF).lstrip('0x').rstrip('L'))
ipv4_int >>= 16
fields.extend(reversed(octets))
+ ip_str = ':'.join(fields)
+ fields = self._explode_shorthand_ip_string(ip_str).split(':')
for field in fields:
try:
ip_int = (ip_int << 16) + int(field or '0', 16)
diff --git a/trunk/ipaddr_test.py b/trunk/ipaddr_test.py
index efc52ca..5d97cf9 100755
--- a/trunk/ipaddr_test.py
+++ b/trunk/ipaddr_test.py
@@ -655,6 +655,15 @@ class IpaddrUnitTest(unittest.TestCase):
self.assertRaises(ipaddr.AddressValueError, ipaddr.IPv6Network,
'2001:1.1.1.1:1.1.1.1')
+ # Issue 67: IPv6 with embedded IPv4 address not recognized.
+ def testIPv6AddressTooLarge(self):
+ # RFC4291 2.5.5.2
+ self.assertEquals(ipaddr.IPAddress('::FFFF:192.0.2.1'),
+ ipaddr.IPAddress('::FFFF:c000:201'))
+ # RFC4291 2.2 (part 3) x::d.d.d.d
+ self.assertEquals(ipaddr.IPAddress('FFFF::192.0.2.1'),
+ ipaddr.IPAddress('FFFF::c000:201'))
+
def testIPVersion(self):
self.assertEqual(self.ipv4.version, 4)
self.assertEqual(self.ipv6.version, 6)