From ee4ab587781f06bb50e0bfd4fb74c228fc27f5dd Mon Sep 17 00:00:00 2001 From: Jack Kleeman Date: Sun, 26 Mar 2017 13:33:16 +0100 Subject: [PATCH] Check for local ip6 addresses with more flexbility Currently IsIPLoopback returns true for any multiaddr starting ip4/127, but only returns true on ip6 addresses that exactly equal ip6/::1. So /ip6/::1/tcp/4001 for example does not return true. Instead we should check whether ip6/::1 is contained in the multiaddr, and to do that I simply decapsulated and checked to see if the result is different. It seems this was not caught by tests as none are present specifically for this function. --- ip.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ip.go b/ip.go index 71a2db6..9d0e251 100644 --- a/ip.go +++ b/ip.go @@ -63,7 +63,7 @@ func IsIPLoopback(m ma.Multiaddr) bool { } // /ip6/::1 - if IP6Loopback.Equal(m) || IP6LinkLocalLoopback.Equal(m) { + if !m.Decapsulate(IP6Loopback).Equal(m) || !m.Decapsulate(IP6LinkLocalLoopback).Equal(m) { return true }