From 88851f2bc954da2914b9d0fffc92814174aff2d9 Mon Sep 17 00:00:00 2001 From: v2ray Date: Sat, 12 Dec 2015 20:57:39 +0100 Subject: [PATCH] Allow IP address is passed as domain in socks5 protocol --- proxy/socks/protocol/socks.go | 8 +++++++- proxy/socks/protocol/udp.go | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/proxy/socks/protocol/socks.go b/proxy/socks/protocol/socks.go index 8210b2308..29a06d23c 100644 --- a/proxy/socks/protocol/socks.go +++ b/proxy/socks/protocol/socks.go @@ -2,6 +2,7 @@ package protocol import ( "io" + "net" "github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/log" @@ -267,7 +268,12 @@ func (request *Socks5Request) Destination() v2net.Destination { case AddrTypeIPv6: address = v2net.IPAddress(request.IPv6[:], request.Port) case AddrTypeDomain: - address = v2net.DomainAddress(request.Domain, request.Port) + maybeIP := net.ParseIP(request.Domain) + if maybeIP != nil { + address = v2net.IPAddress(maybeIP, request.Port) + } else { + address = v2net.DomainAddress(request.Domain, request.Port) + } default: panic("Unknown address type") } diff --git a/proxy/socks/protocol/udp.go b/proxy/socks/protocol/udp.go index 82af3c4f4..1730c9077 100644 --- a/proxy/socks/protocol/udp.go +++ b/proxy/socks/protocol/udp.go @@ -2,6 +2,7 @@ package protocol import ( "errors" + "net" "github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/log" @@ -73,7 +74,12 @@ func ReadUDPRequest(packet []byte) (*Socks5UDPRequest, error) { } domain := string(packet[5 : 5+domainLength]) port := v2net.PortFromBytes(packet[5+domainLength : 5+domainLength+2]) - request.Address = v2net.DomainAddress(domain, port) + maybeIP := net.ParseIP(domain) + if maybeIP != nil { + request.Address = v2net.IPAddress(maybeIP, port) + } else { + request.Address = v2net.DomainAddress(domain, port) + } dataBegin = 5 + domainLength + 2 default: log.Warning("Unknown address type %d", addrType)