diff --git a/README.md b/README.md index c6e3c8a..e03d19b 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu * [Ori Bernstein](https://eigenstate.org) * [Sam Lancia](https://github.com/nerd2) * [Lander Noterman](https://github.com/LanderN) +* [BUPTCZQ](https://github.com/buptczq) * [Henry](https://github.com/cryptix) ### License diff --git a/util.go b/util.go index f9d6cd3..e287efd 100644 --- a/util.go +++ b/util.go @@ -25,7 +25,7 @@ func (a *atomicError) Load() error { // https://tools.ietf.org/html/rfc8445#section-5.1.1.1 func isSupportedIPv6(ip net.IP) bool { if len(ip) != net.IPv6len || - !isZeros(ip[0:12]) || // !(IPv4-compatible IPv6) + isZeros(ip[0:12]) || // !(IPv4-compatible IPv6) ip[0] == 0xfe && ip[1]&0xc0 == 0xc0 || // !(IPv6 site-local unicast) ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() { diff --git a/util_test.go b/util_test.go new file mode 100644 index 0000000..d73aec4 --- /dev/null +++ b/util_test.go @@ -0,0 +1,28 @@ +package ice + +import ( + "net" + "testing" +) + +func TestIsSupportedIPv6(t *testing.T) { + if isSupportedIPv6(net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}) { + t.Errorf("isSupportedIPv6 return true with IPv4-compatible IPv6 address") + } + + if isSupportedIPv6(net.ParseIP("fec0::2333")) { + t.Errorf("isSupportedIPv6 return true with IPv6 site-local unicast address") + } + + if isSupportedIPv6(net.ParseIP("fe80::2333")) { + t.Errorf("isSupportedIPv6 return true with IPv6 link-local address") + } + + if isSupportedIPv6(net.ParseIP("ff02::2333")) { + t.Errorf("isSupportedIPv6 return true with IPv6 link-local multicast address") + } + + if !isSupportedIPv6(net.ParseIP("2001::1")) { + t.Errorf("isSupportedIPv6 return false with IPv6 global unicast address") + } +}