Skip to content

Improve the textual representation of IPv4-mapped IPv6 addresses #87799

Closed

Description

@maxmouchet
BPO 43633
Nosy @opavlyuk, @maxmouchet
PRs
  • gh-87799: Improve the textual representation of IPv4-mapped IPv6 addresses #29345
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2021-03-26.17:34:40.530>
    labels = ['type-feature', 'library']
    title = 'Improve the textual representation of IPv4-mapped IPv6 addresses'
    updated_at = <Date 2021-11-01.12:05:04.773>
    user = 'https://github.com/maxmouchet'

    bugs.python.org fields:

    activity = <Date 2021-11-01.12:05:04.773>
    actor = 'opavlyuk'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2021-03-26.17:34:40.530>
    creator = 'maxmouchet'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43633
    keywords = ['patch']
    message_count = 2.0
    messages = ['389556', '405434']
    nosy_count = 2.0
    nosy_names = ['opavlyuk', 'maxmouchet']
    pr_nums = ['29345']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue43633'
    versions = []

    Linked PRs

    Activity

    1. maxmouchet commented on Mar 26, 2021

      maxmouchetmannequin
      MannequinAuthor

      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:

         from ipaddress import ip_address
         addr = ip_address('::ffff:8.8.4.4') # IPv6Address('::ffff:808:404')
         addr.ipv4_mapped # IPv4Address('8.8.4.4')

      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 :

         from ipaddress import ip_address
         addr = ip_address('::ffff:8.8.4.4')
      
         # Current behavior
         str(addr)  # '::ffff:808:404'
         repr(addr) # IPv6Address('::ffff:808:404')
      
         # Proposed behavior
         str(addr)  # '::ffff:8.8.4.4'
         repr(addr) # IPv6Address('::ffff:8.8.4.4')

      A few data points:

      • Julia prints ::ffff:808:404 (current behavior)
      • C (glibc) and ClickHouse prints ::ffff:8.8.4.4 (proposed behavior)
    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on Mar 26, 2021
    3. opavlyuk commented on Nov 1, 2021

      opavlyukmannequin
      Mannequin

      @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.

    4. transferred this issue fromon Apr 10, 2022
    5. added a commit that references this issue on Jul 31, 2023
    6. asvetlov commented on Jul 31, 2023

      @asvetlov
      Contributor

      Done by #29345

    7. kellyjonbrazil commented on Aug 1, 2024

      @kellyjonbrazil

      Are there any tests for the reverse_pointer method? I'm seeing strange results with the new behavior:

      IP Address: ::FFFF:192.168.1.35

      Results in a reverse_pointer of:

      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.arpa

      instead 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.arpa

      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)

    8. added a commit that references this issue on Sep 2, 2024
    9. added a commit that references this issue on Sep 2, 2024
    10. added a commit that references this issue on Sep 2, 2024
    11. added 4 commits that reference this issue on Jun 3, 2025
    12. added 3 commits that reference this issue on Jun 3, 2025
    13. added 3 commits that reference this issue on Jun 3, 2025
    14. added a commit that references this issue on Jun 3, 2025
    15. added a commit that references this issue on Jun 3, 2025
    16. added 4 commits that reference this issue on Jun 3, 2025
    17. oprypin commented on Jun 4, 2025

      @oprypin

      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.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.13only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions