Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
maxmouchet mannequin opened this issue Mar 26, 2021 · 3 comments
Closed

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

maxmouchet mannequin opened this issue Mar 26, 2021 · 3 comments
Labels
3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@maxmouchet
Copy link
Mannequin

maxmouchet mannequin commented Mar 26, 2021

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 = []

    @maxmouchet
    Copy link
    Mannequin Author

    maxmouchet mannequin commented 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:

       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)

    @maxmouchet maxmouchet mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 26, 2021
    @opavlyuk
    Copy link
    Mannequin

    opavlyuk mannequin commented 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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @arhadthedev arhadthedev added the 3.13 new features, bugs and security fixes label May 13, 2023
    asvetlov added a commit that referenced this issue Jul 31, 2023
    …esses (#29345)
    
    Represent IPv4-mapped IPv6 address as x:x:x:x:x:x:d.d.d.d,
    where the 'x's are the hexadecimal values
    of the six high-order 16-bit pieces of the address,
    and the 'd's are the decimal values
    of the four low-order 8-bit pieces of the address
    (standard IPv4 representation).
    
    ---------
    
    Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
    Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
    @asvetlov
    Copy link
    Contributor

    Done by #29345

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants