diff --git a/ip.go b/ip.go index d188957..421dddf 100644 --- a/ip.go +++ b/ip.go @@ -14,8 +14,8 @@ var ( // IP6Loopback is the ip6 loopback multiaddr IP6Loopback = ma.StringCast("/ip6/::1") - // IP6LinkLocalLoopback is the ip6 link-local loopback multiaddr - IP6LinkLocalLoopback = ma.StringCast("/ip6/fe80::1") + // IP4MappedIP6Loopback is the IPv4 Mapped IPv6 loopback address. + IP4MappedIP6Loopback = ma.StringCast("/ip6/::ffff:127.0.0.1") ) // Unspecified Addresses (used for ) @@ -28,8 +28,8 @@ var ( // following byte sequences is considered a loopback multiaddr. var loopbackPrefixes = [][]byte{ {ma.P_IP4, 127}, // 127.* - IP6LinkLocalLoopback.Bytes(), - IP6Loopback.Bytes(), + {ma.P_IP6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 127}, // ::ffff:127.* + IP6Loopback.Bytes(), // ::1 } // IsThinWaist returns whether a Multiaddr starts with "Thin Waist" Protocols. diff --git a/net_test.go b/net_test.go index 9454fe2..553dcba 100644 --- a/net_test.go +++ b/net_test.go @@ -306,8 +306,8 @@ func TestIPLoopback(t *testing.T) { t.Error("IP6Loopback incorrect:", IP6Loopback) } - if IP6LinkLocalLoopback.String() != "/ip6/fe80::1" { - t.Error("IP6LinkLocalLoopback incorrect:", IP6Loopback) + if IP4MappedIP6Loopback.String() != "/ip6/127.0.0.1" { + t.Error("IP4MappedIP6Loopback incorrect:", IP4MappedIP6Loopback) } if !IsIPLoopback(IP4Loopback) { @@ -330,8 +330,16 @@ func TestIPLoopback(t *testing.T) { t.Error("IsIPLoopback failed (IP6Loopback)") } - if !IsIPLoopback(IP6LinkLocalLoopback) { - t.Error("IsIPLoopback failed (IP6LinkLocalLoopback)") + if !IsIPLoopback(newMultiaddr(t, "/ip6/127.0.0.1")) { + t.Error("IsIPLoopback failed (/ip6/127.0.0.1)") + } + + if !IsIPLoopback(newMultiaddr(t, "/ip6/127.99.3.2")) { + t.Error("IsIPLoopback failed (/ip6/127.99.3.2)") + } + + if IsIPLoopback(newMultiaddr(t, "/ip6/::fffa:127.99.3.2")) { + t.Error("IsIPLoopback false positive (/ip6/::fffa:127.99.3.2)") } } @@ -354,10 +362,6 @@ func TestIPUnspecified(t *testing.T) { } func TestIP6LinkLocal(t *testing.T) { - if !IsIP6LinkLocal(IP6LinkLocalLoopback) { - t.Error("IsIP6LinkLocal failed (IP6LinkLocalLoopback)") - } - for a := 0; a < 65536; a++ { isLinkLocal := (a == 0xfe80) m := newMultiaddr(t, fmt.Sprintf("/ip6/%x::1", a))