Fix IPv6 addresses gathering

Fix isSupportedIPv6 function, when a global unicast address passed to,
the function returns false.

Resolves #176
This commit is contained in:
buptczq
2020-07-02 23:05:34 -07:00
committed by Sean DuBois
parent c51782f04c
commit ee0d28c779
3 changed files with 30 additions and 1 deletions
+1
View File
@@ -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
+1 -1
View File
@@ -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() {
+28
View File
@@ -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")
}
}