diff options
author | pmoody@google.com <pmoody@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035> | 2011-01-12 22:56:45 +0000 |
---|---|---|
committer | pmoody@google.com <pmoody@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035> | 2011-01-12 22:56:45 +0000 |
commit | 250baa3feaaca651955ddb53324e4ff9faaf278f (patch) | |
tree | 985c587bd6efc4a0ef470e4902cdfe289f94c551 /trunk | |
parent | 41a77f12c91d9348362e38f8fe00df235b85e907 (diff) | |
download | ipaddr-py-250baa3feaaca651955ddb53324e4ff9faaf278f.tar.gz |
+ add 6to4 to the ipv6 tunnel decoding.
git-svn-id: https://ipaddr-py.googlecode.com/svn@201 09200d28-7f98-11dd-ad27-0f66e57d2035
Diffstat (limited to 'trunk')
-rw-r--r-- | trunk/ipaddr.py | 21 | ||||
-rwxr-xr-x | trunk/ipaddr_test.py | 10 |
2 files changed, 28 insertions, 3 deletions
diff --git a/trunk/ipaddr.py b/trunk/ipaddr.py index dff40d3..261f3e2 100644 --- a/trunk/ipaddr.py +++ b/trunk/ipaddr.py @@ -1753,15 +1753,30 @@ class _BaseV6(object): """Tuple of embedded teredo IPs. Returns: - Tuple of the (server, client) IPs. + Tuple of the (server, client) IPs or False if the address + doesn't appear to be a teredo address (doesn't start with + 2001) - Note: - This doesn't try to verify that the address is a teredo address """ bits = self._explode_shorthand_ip_string().split(':') + if not bits[0] == '2001': + return False return (IPv4Address(int(''.join(bits[2:4]), 16)), IPv4Address(int(''.join(bits[6:]), 16) ^ 0xFFFFFFFF)) + def sixtofour(self): + """Return the IPv4 6to4 embedded address. + + Returns: + The IPv4 6to4-embedded address if present or False if the + address doesn't appear to contain a 6to4 embedded address. + + """ + bits = self._explode_shorthand_ip_string().split(':') + if not bits[0] == '2002': + return False + return IPv4Address(int(''.join(bits[1:3]), 16)) + class IPv6Address(_BaseV6, _BaseIP): diff --git a/trunk/ipaddr_test.py b/trunk/ipaddr_test.py index 739c5f6..657ac99 100755 --- a/trunk/ipaddr_test.py +++ b/trunk/ipaddr_test.py @@ -1024,6 +1024,16 @@ class IpaddrUnitTest(unittest.TestCase): teredo_addr = '2001:0000:4136:e378:8000:63bf:3fff:fdd2' self.assertEqual((server, client), ipaddr.IPAddress(teredo_addr).teredo()) + bad_addr = '2000::4136:e378:8000:63bf:3fff:fdd2' + self.assertFalse(ipaddr.IPAddress(bad_addr).teredo()) + + def testsixtofour(self): + sixtofouraddr = ipaddr.IPAddress('2002:ac1d:2d64::1') + bad_addr = ipaddr.IPAddress('2000:ac1d:2d64::1') + self.assertEqual(ipaddr.IPv4Address('172.29.45.100'), + sixtofouraddr.sixtofour()) + self.assertFalse(bad_addr.sixtofour()) + if __name__ == '__main__': unittest.main() |