You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve the textual representation of IPv4-mapped IPv6 addresses #87799
Note that the textual representation of the IPv6Address is *not* in IPv4-mapped format.
It prints ::ffff:808:404 instead of ::ffff:8.8.4.4.
This is technically correct, but it’s somewhat frustrating as it makes it harder to read IPv4s embedded in IPv6 addresses.
My proposal would be to check, in __str__, if an IPv6 is an IPv4-mapped, and to return the appropriate representation :
I'm not sure which one is more valid or if a pointer record is even relevant in the context of mapped addresses. The original way seems more correct to me if nothing for the fact that there are strange extra dots in the new output.
(I'll create a new issue for this since this one is closed)
I'd like to express my concern that this change got backported to all these patch releases of Python. Surely the feature is not so important that everyone needs to get it immediately? Compared to the tradeoff that this is supposed to be bugfixes-only?
As I'm rushing to apply the latest security release, I see that the patch release also changed our code that produces IPv6 addresses to now produce ::ffff:7.8.9.10 instead of ::ffff:708:90a.
Activity
maxmouchet commentedon Mar 26, 2021
Python supports IPv4-mapped IPv6 addresses as defined by RFC 4038:
"the IPv6 address ::FFFF:x.y.z.w represents the IPv4 address x.y.z.w.”
The current behavior is as follows:
Note that the textual representation of the IPv6Address is *not* in IPv4-mapped format.
It prints ::ffff:808:404 instead of ::ffff:8.8.4.4.
This is technically correct, but it’s somewhat frustrating as it makes it harder to read IPv4s embedded in IPv6 addresses.
My proposal would be to check, in __str__, if an IPv6 is an IPv4-mapped, and to return the appropriate representation :
A few data points:
opavlyuk commentedon Nov 1, 2021
@maxmouchet, thank you for creating the issue.
For me it makes sense, and RFC 4291 calls such IPv6 text representation approach as "more convenient".
I'll try to fix this, if you don't mind.
P.S.: Sorry for providing PR before I asked.
gh-87799: Improve the textual representation of IPv4-mapped IPv6 addr…
asvetlov commentedon Jul 31, 2023
Done by #29345
kellyjonbrazil commentedon Aug 1, 2024
Are there any tests for the
reverse_pointermethod? I'm seeing strange results with the new behavior:IP Address:
::FFFF:192.168.1.35Results in a
reverse_pointerof:5.3...1...8.6.1...2.9.1.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.arpainstead of the old:
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.arpaI'm not sure which one is more valid or if a pointer record is even relevant in the context of mapped addresses. The original way seems more correct to me if nothing for the fact that there are strange extra dots in the new output.
(I'll create a new issue for this since this one is closed)
gh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped addresses (
pythongh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped ad…
[3.13] gh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped a…
pythongh-87799: Improve the textual representation of IPv4-mapped IPv…
pythongh-87799: Improve the textual representation of IPv4-mapped IPv…
pythongh-87799: Improve the textual representation of IPv4-mapped IPv…
pythongh-87799: Improve the textual representation of IPv4-mapped IPv…
[3.11] gh-87799: Improve the textual representation of IPv4-mapped IP…
[3.12] gh-87799: Improve the textual representation of IPv4-mapped IP…
[3.9] gh-87799: Improve the textual representation of IPv4-mapped IPv…
pythongh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped ad…
pythongh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped ad…
pythongh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped ad…
[3.10] gh-87799: Improve the textual representation of IPv4-mapped IP…
pythongh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped ad…
[3.10] gh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped a…
[3.11] gh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped a…
[3.12] gh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped a…
[3.9] gh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped ad…
oprypin commentedon Jun 4, 2025
I'd like to express my concern that this change got backported to all these patch releases of Python. Surely the feature is not so important that everyone needs to get it immediately? Compared to the tradeoff that this is supposed to be bugfixes-only?
As I'm rushing to apply the latest security release, I see that the patch release also changed our code that produces IPv6 addresses to now produce
::ffff:7.8.9.10instead of::ffff:708:90a.