From 5a9913eca51fdab64a7e6e4fdaa95b7f4b2c4b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 12 Sep 2022 11:33:38 +0800 Subject: [PATCH] Fix socks4 client --- outbound/socks.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/outbound/socks.go b/outbound/socks.go index 2400e427..61318c33 100644 --- a/outbound/socks.go +++ b/outbound/socks.go @@ -20,8 +20,9 @@ var _ adapter.Outbound = (*Socks)(nil) type Socks struct { myOutboundAdapter - client *socks.Client - uot bool + client *socks.Client + resolve bool + uot bool } func NewSocks(router adapter.Router, logger log.ContextLogger, tag string, options option.SocksOutboundOptions) (*Socks, error) { @@ -45,6 +46,7 @@ func NewSocks(router adapter.Router, logger log.ContextLogger, tag string, optio tag: tag, }, socks.NewClient(detour, options.ServerOptions.Build(), version, options.Username, options.Password), + version == socks.Version4, options.UoT, }, nil } @@ -72,6 +74,13 @@ func (h *Socks) DialContext(ctx context.Context, network string, destination M.S default: return nil, E.Extend(N.ErrUnknownNetwork, network) } + if destination.IsFqdn() { + addrs, err := h.router.LookupDefault(ctx, destination.Fqdn) + if err != nil { + return nil, err + } + return N.DialSerial(ctx, h.client, network, destination, addrs) + } return h.client.DialContext(ctx, network, destination) }