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/netip: disagrees with net.ParseIP on v4on6 #50844

Closed
anacrolix opened this issue Jan 27, 2022 · 4 comments
Closed

net/netip: disagrees with net.ParseIP on v4on6 #50844

anacrolix opened this issue Jan 27, 2022 · 4 comments
Labels
NeedsInvestigation
Milestone

Comments

@anacrolix
Copy link
Contributor

@anacrolix anacrolix commented Jan 27, 2022

net/netip.Addr obtained via strings, vs. from slices don't compare as expected.

https://go.dev/play/p/Bsrg-fO6eRk?v=gotip

I think the issue boils down to net.ParseIP always essentially returning what net/netip.Addr would consider a v4on6 for IPv4 addresses. The workaround is to bypass net.ParseIP. I'm not sure if it's expected that ip and netip should differ here, and whether it would be breaking compatibility guarantees for ParseIP to return a 4 byte slice for a dotted address string. Perhaps there should be some kind of conversion function/method to smooth the disagreement over?

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 27, 2022

CC @bradfitz @josharian

@ianlancetaylor ianlancetaylor added the NeedsInvestigation label Jan 27, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Jan 27, 2022
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Jan 27, 2022

This is all by design. Fixing the 4in6 handling of the net package was one of the original motivations of the new package.

If there are any documentation omissions, let us know, but I believe this is all documented (and extensively tested & fuzzed)

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 29, 2022

Thanks, closing. Please comment if you disagree.

@Fndroid
Copy link

@Fndroid Fndroid commented Jan 31, 2022

If netip.ParseAddr returns ipv6 if we pass a v4in6 address as the argument. Will this behavior break net.Dial?

Should we convert it manually?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

4 participants