1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-04-04 12:56:01 -04:00

Fix for IPv4 address

This commit is contained in:
V2Ray
2015-10-14 08:43:04 +02:00
parent 8408b7735c
commit 2a00e2c6e9
2 changed files with 23 additions and 0 deletions

View File

@@ -22,6 +22,15 @@ type Address interface {
String() string // String representation of this Address
}
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, port uint16) Address {
switch len(ip) {
@@ -31,6 +40,9 @@ func IPAddress(ip []byte, port uint16) Address {
ip: [4]byte{ip[0], ip[1], ip[2], ip[3]},
}
case net.IPv6len:
if allZeros(ip[0:10]) && ip[10] == 0xff && ip[11] == 0xff {
return IPAddress(ip[12:16], port)
}
return IPv6Address{
PortAddress: PortAddress{port: port},
ip: [16]byte{