mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
[3.13] gh-122792: Make IPv4-mapped IPv6 address properties consistent with IPv4 (GH-122793) (GH-123815)
Make IPv4-mapped IPv6 address properties consistent with IPv4.
(cherry picked from commit 76a1c5d183
)
Co-authored-by: Seth Michael Larson <seth@python.org>
This commit is contained in:
parent
3479a719b8
commit
a63e06d95b
3 changed files with 42 additions and 0 deletions
|
@ -2442,6 +2442,30 @@ class IpaddrUnitTest(unittest.TestCase):
|
|||
self.assertEqual(ipaddress.ip_address('::ffff:c0a8:101').ipv4_mapped,
|
||||
ipaddress.ip_address('192.168.1.1'))
|
||||
|
||||
def testIpv4MappedProperties(self):
|
||||
# Test that an IPv4 mapped IPv6 address has
|
||||
# the same properties as an IPv4 address.
|
||||
for addr4 in (
|
||||
"178.62.3.251", # global
|
||||
"169.254.169.254", # link local
|
||||
"127.0.0.1", # loopback
|
||||
"224.0.0.1", # multicast
|
||||
"192.168.0.1", # private
|
||||
"0.0.0.0", # unspecified
|
||||
"100.64.0.1", # public and not global
|
||||
):
|
||||
with self.subTest(addr4):
|
||||
ipv4 = ipaddress.IPv4Address(addr4)
|
||||
ipv6 = ipaddress.IPv6Address(f"::ffff:{addr4}")
|
||||
|
||||
self.assertEqual(ipv4.is_global, ipv6.is_global)
|
||||
self.assertEqual(ipv4.is_private, ipv6.is_private)
|
||||
self.assertEqual(ipv4.is_reserved, ipv6.is_reserved)
|
||||
self.assertEqual(ipv4.is_multicast, ipv6.is_multicast)
|
||||
self.assertEqual(ipv4.is_unspecified, ipv6.is_unspecified)
|
||||
self.assertEqual(ipv4.is_link_local, ipv6.is_link_local)
|
||||
self.assertEqual(ipv4.is_loopback, ipv6.is_loopback)
|
||||
|
||||
def testIpv4MappedPrivateCheck(self):
|
||||
self.assertEqual(
|
||||
True, ipaddress.ip_address('::ffff:192.168.1.1').is_private)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue