diff --git a/common/protocol/address.go b/common/protocol/address.go index d728798a8..9d391e8e3 100644 --- a/common/protocol/address.go +++ b/common/protocol/address.go @@ -3,11 +3,10 @@ package protocol import ( "io" - "v2ray.com/core/common/task" - "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" + "v2ray.com/core/common/task" ) type AddressOption func(*AddressParser) @@ -110,7 +109,7 @@ func (p *AddressParser) readAddress(b *buf.Buffer, reader io.Reader) (net.Addres domain := string(b.BytesFrom(-domainLength)) if maybeIPPrefix(domain[0]) { addr := net.ParseAddress(domain) - if addr.Family().IsIPv4() || addrFamily.IsIPv6() { + if addr.Family().IsIPv4() || addr.Family().IsIPv6() { return addr, nil } } diff --git a/common/protocol/address_test.go b/common/protocol/address_test.go index d66d119e5..e9bd75226 100644 --- a/common/protocol/address_test.go +++ b/common/protocol/address_test.go @@ -69,6 +69,12 @@ func TestAddressReading(t *testing.T) { Input: []byte{3, 7, 10, 46, 56, 46, 56, 46, 56, 0, 80}, Error: true, }, + { + Options: []AddressOption{AddressFamilyByte(0x03, net.AddressFamilyDomain)}, + Input: append(append([]byte{3, 24}, []byte("2a00:1450:4007:816::200e")...), 0, 80), + Address: net.ParseAddress("2a00:1450:4007:816::200e"), + Port: net.Port(80), + }, } for _, tc := range data { @@ -79,9 +85,9 @@ func TestAddressReading(t *testing.T) { if tc.Error { assert(err, IsNotNil) } else { + assert(err, IsNil) assert(addr, Equals, tc.Address) assert(port, Equals, tc.Port) - assert(err, IsNil) } } }