Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -2056,15 +2056,9 @@ def _explode_shorthand_ip_string(self):
return f"{raw_exploded_str[:prefix_len]}{ipv4_mapped!s}"

def _reverse_pointer(self):
ipv4_mapped = self.ipv4_mapped
if ipv4_mapped is None:
return super()._reverse_pointer()
prefix_len = 30
raw_exploded_str = super()._explode_shorthand_ip_string()[:prefix_len]
# ipv4 encoded using hexadecimal nibbles instead of decimals
ipv4_int = ipv4_mapped._ip
reverse_chars = f"{raw_exploded_str}{ipv4_int:008x}"[::-1].replace(':', '')
return '.'.join(reverse_chars) + '.ip6.arpa'
# Built from the integer so that neither the scope ID nor the
# IPv4-mapped dotted form ends up in the name.
return '.'.join(f'{self._ip:032x}'[::-1]) + '.ip6.arpa'

def _ipv4_mapped_ipv6_to_str(self):
"""Return convenient text representation of IPv4-mapped IPv6 address
Expand Down
24 changes: 23 additions & 1 deletion Lib/test/test_ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -2850,7 +2850,29 @@ def testReversePointer(self):
'2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.'
'ip6.arpa'
)
)
),
# a scope id is not part of the pointer name
(
'fe80::1%eth0', (
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.'
'0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.'
'ip6.arpa'
)
),
(
'fe80::1%1', (
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.'
'0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.'
'ip6.arpa'
)
),
(
'::FFFF:192.168.1.35%eth0', (
'3.2.1.0.8.a.0.c.f.f.f.f.0.0.0.0.'
'0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.'
'ip6.arpa'
)
),
]:
with self.subTest('ipv6_reverse_pointer', addr=addr_v6):
addr = ipaddress.IPv6Address(addr_v6)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :attr:`ipaddress.IPv6Address.reverse_pointer` returning an invalid name
for an address with a scope ID. The scope ID is not part of the reverse DNS
name and is no longer included in it.
Loading