1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-06 09:15:37 -05:00

BytesLiteral.All()

This commit is contained in:
Darien Raymond
2016-01-21 11:52:09 +00:00
parent c78460df1e
commit 85feb725a5
3 changed files with 7 additions and 13 deletions

View File

@@ -4,6 +4,7 @@ import (
"net"
"github.com/v2ray/v2ray-core/common/log"
"github.com/v2ray/v2ray-core/common/serial"
)
// Address represents a network address to be communicated with. It may be an IP address or domain
@@ -28,15 +29,6 @@ func ParseAddress(addr string) Address {
return DomainAddress(addr)
}
func allZeros(data []byte) bool {
for _, v := range data {
if v != 0 {
return false
}
}
return true
}
// IPAddress creates an Address with given IP and port.
func IPAddress(ip []byte) Address {
switch len(ip) {
@@ -44,7 +36,7 @@ func IPAddress(ip []byte) Address {
var addr IPv4Address = [4]byte{ip[0], ip[1], ip[2], ip[3]}
return &addr
case net.IPv6len:
if allZeros(ip[0:10]) && ip[10] == 0xff && ip[11] == 0xff {
if serial.BytesLiteral(ip[0:10]).All(0) && serial.BytesLiteral(ip[10:12]).All(0xff) {
return IPAddress(ip[12:16])
}
var addr IPv6Address = [16]byte{