You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that in this documentation, referring to an IP address as an IPv4 address or an IPv6 address is a semantic property of the address, not just the length of the byte slice: a 16-byte slice can still be an IPv4 address.
In particular, you're seeing an IPv4 address embedded in an IPv6 address.
If you want a 4-byte representation, use the To4 method.
dominikh
changed the title
unexpected padding byte when convert from net.IP to []byte
net: unexpected padding byte when convert from net.IP to []byte
Nov 2, 2018
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
)?go env
OutputWhat did you do?
https://play.golang.org/p/gtcQZajAmBN
package main
import (
"fmt"
"net"
)
func main() {
myIP, _, _ := net.ParseCIDR("127.0.0.1/24")
fmt.Printf("%v\n", []byte(myIP))
}
What did you expect to see?
[127 0 0 1]
What did you see instead?
[0 0 0 0 0 0 0 0 0 0 255 255 127 0 0 1]
The text was updated successfully, but these errors were encountered: