fix: handle metadata when dst is ip:port

This commit is contained in:
Skyxim 2022-04-28 12:44:27 +08:00
parent 22c1e05e1c
commit c7bc67e44c

View file

@ -2,6 +2,7 @@ package inbound
import ( import (
"net" "net"
"net/netip"
C "github.com/Dreamacro/clash/constant" C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/context" "github.com/Dreamacro/clash/context"
@ -36,7 +37,13 @@ func NewInner(conn net.Conn, dst string, host string) *context.ConnContext {
if h, port, err := net.SplitHostPort(dst); err == nil { if h, port, err := net.SplitHostPort(dst); err == nil {
metadata.DstPort = port metadata.DstPort = port
if host == "" { if host == "" {
metadata.Host = h if ip, err := netip.ParseAddr(h); err == nil {
metadata.DstIP = ip
metadata.AddrType = C.AtypIPv4
if ip.Is6() {
metadata.AddrType = C.AtypIPv6
}
}
} }
} }