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.IPFromString misparses ::ffff:0.0.0.0 #477

Open
taktv6 opened this issue Aug 1, 2024 · 0 comments
Open

net.IPFromString misparses ::ffff:0.0.0.0 #477

taktv6 opened this issue Aug 1, 2024 · 0 comments

Comments

@taktv6
Copy link
Member

taktv6 commented Aug 1, 2024

Describe the bug
When parsing ::ffff:0.0.0.0 net.IPFromString returns an all zero IPv4 address while IPv6 is expected.

Steps to Reproduce


import (
	"fmt"
	"net"

	bnet "github.com/bio-routing/bio-rd/net"
)

func main() {
	bio()
	upstream()
}

func upstream() {
	fmt.Printf("golang net:\n")
	ip := net.ParseIP("::ffff:0.0.0.0")
	v4 := ip.To4()
	if v4 != nil {
		fmt.Printf("is IPv4!\n")
	}

	v6 := ip.To16()
	if v6 != nil {
		fmt.Printf("Is IPv6!\n")
	}

	fmt.Printf("v4: %s\n", v4.String())
	fmt.Printf("v6: %s\n", v6.String())
}

func bio() {
	fmt.Printf("bio net:\n")
	ip, err := bnet.IPFromString("::ffff:0.0.0.0")
	if err != nil {
		panic(err)
	}

	fmt.Printf("Is IPv4: %v\n", ip.IsIPv4())

	fmt.Printf("Addr: %s\n", ip.String())
}
Is IPv4: true
Addr: 0.0.0.0
golang net:
is IPv4!
Is IPv6!
v4: 0.0.0.0
v6: 0.0.0.0```
**Expected behavior**
net.IPFromString should return `::ffff:0.0.0.0` or `::ffff:0:0`

**Additional context**
This behavior was inherited from upstream net.ParseIP function. It basically casts any IPv6 mapped IPv4 address into a pure IPv4 address from which it is not possible to detect that it actually was an IPv6 address.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant