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
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@anacrolix
Copy link
Contributor

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

CC @bradfitz @josharian

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 27, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Jan 27, 2022
@bradfitz
Copy link
Contributor

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

Thanks, closing. Please comment if you disagree.

@Fndroid
Copy link

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?

@golang golang locked and limited conversation to collaborators Jan 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants