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

Comments

Projects
None yet
5 participants
@dmitryrpm
Copy link

commented Jul 30, 2018

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 this to the Unplanned milestone Jul 30, 2018

@andybons

This comment has been minimized.

Copy link
Member

commented Jul 30, 2018

@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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Contributor

commented Aug 1, 2018

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

This comment has been minimized.

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.