-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: ip.To4() question #33535
Comments
Mapped IPv4 addresses should have a prefix of 80 zero bits followed by 16 one bits. So, for example, this: func main() {
_, test1, _ := net.ParseCIDR("::ffff:0:0/113")
fmt.Println(test1.String())
} does what you would expect. (https://play.golang.org/p/G2oL_tzc4PJ) This 96 zero bit prefix that you're using does not have any special meaning as far as I can tell: https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml |
@ccahoon it doesn't have any special meaning but it's clear that it's not a legal IPv6 address. The issue is probably since the library: https://github.com/oschwald/maxminddb-golang This is another way of converting the net.IPNet to a v4 inside a v6 16 bytes array: |
You acknowledge that the form in question doesn't have any special meaning commonly attached to it. Yet, you propose to handle it in a very specific (and seemingly arbitrary) way. What's the reasoning for this?
The loopback address, ::1/128, for one. |
The reason for this address is since the maxmindDB files stores it either wrongly or the library reading it doing something wrong..
|
@slrz It apears that maxmindDB structure holds at least two copies of the an IPv4 inside and IPv6 mapped DB. They probably do that to be compatible with old libraries. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?Debian 10 Buster amd64
go env
OutputWhat did you do?
Used the library: https://github.com/oschwald/maxminddb-golang
with a v4+v6(4 as 6) DB to export a set of Countries IP CIDR's.
Then print the net.IPNet object as string.
The output is:
https://play.golang.org/p/y-A-SC8fs9u
What did you expect to see?
The net.IPNet to print the right IPv4 CIDR as:
1.1.0.0/24
and not as IPv6:
::101:0/120
What did you see instead?
I wrote a function that validates and converts the IPv6 16 Bytes array to a 4 Bytes array.
The text was updated successfully, but these errors were encountered: