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

net: ParseIP for IPv6 with embedded IPv4 incorrect parsing #26694

Closed
dmitryrpm opened this issue Jul 30, 2018 · 5 comments
Closed

net: ParseIP for IPv6 with embedded IPv4 incorrect parsing #26694

dmitryrpm opened this issue Jul 30, 2018 · 5 comments

Comments

@dmitryrpm
Copy link

Hi, I got a strange result when do parsing IPv6:IPv4 (mixed-form), no by rfc3513
0:0:0:0:0:0:13.1.68.3 -> ::d01:4403

fmt.Printf("Result compresed form: %s", net.ParseIP("0:0:0:0:0:0:13.1.68.3").String())
>>> Result compresed form: ::d01:4403 // need ::13.1.68.3

https://play.golang.org/p/mPH9cANDRVO

Is it real correct parsing?

@dmitryrpm dmitryrpm changed the title net IPv6 parsing net.ParseIP (IPv6:IPv4 mixed-form) incorrect parsing Jul 30, 2018
@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 30, 2018
@andybons andybons added this to the Unplanned milestone Jul 30, 2018
@andybons
Copy link
Member

@mikioh @bradfitz

@andybons andybons changed the title net.ParseIP (IPv6:IPv4 mixed-form) incorrect parsing net: ParseIP (IPv6:IPv4 mixed-form) incorrect parsing Jul 30, 2018
@ajwsh
Copy link

ajwsh commented Jul 30, 2018

Yes, it is parsed correctly. What you get is the hexadecimal representation of the mixed address. In an IPv6 address you got 8 groups consisting of 16 bit each. In a IPv4 address are 4 groups consisting of 8 bits each. So your IPv4 will be represented in hexadecimal as 0x0d01 (= 13.1) and 0x4403 (= 68.3).
A more detailed explanation can be found here: https://en.wikipedia.org/wiki/IPv6_address#Representation

@dmitryrpm
Copy link
Author

dmitryrpm commented Jul 31, 2018

@ajwsh Thank for a answer!
but in other example I have not convert IPv4 to hex. Why? =)
"0:0:0:0:0:FFFF:129.144.52.38" => 129.144.52.38 // other rfc exmpale need ::FFFF:129.144.52.38
https://play.golang.org/p/W_YRWzgwUZB

For example, the IPv4-mapped IPv6 address ::ffff:c000:0280 is written as ::ffff:192.0.2.128, thus expressing clearly the original IPv4 address that was mapped to IPv6

@ianlancetaylor
Copy link
Contributor

It sounds like things are working correctly. We don't use the issue tracker for questions; please see https://golang.org/wiki/Questions . Thanks.

(I don't know the answer to your question myself.)

@mikioh mikioh removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 1, 2018
@mikioh
Copy link
Contributor

mikioh commented Aug 1, 2018

In general, it's better to refer to the latest addressing architecture, RFC 4291, instead of RFC 3513. RFC 4291 holds better descriptions on the section "IPv6 Addresses with Embedded IPv4 Addresses", and has a reference to RFC 4038 (Application Aspects of IPv6 Transition).

So taking a look at https://tools.ietf.org/html/rfc4291 will probably answer your question.

@mikioh mikioh changed the title net: ParseIP (IPv6:IPv4 mixed-form) incorrect parsing net: ParseIP for IPv6 with embedded IPv4 incorrect parsing Aug 1, 2018
@golang golang locked and limited conversation to collaborators Aug 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants