fix: proxyDialer panic when domain name was not resolved

This commit is contained in:
wwqgtxx
2023-04-12 12:49:53 +08:00
parent 17922dc857
commit 20eb168315
5 changed files with 45 additions and 35 deletions

View File

@ -229,3 +229,21 @@ func (m *Metadata) String() string {
func (m *Metadata) Valid() bool {
return m.Host != "" || m.DstIP.IsValid()
}
func (m *Metadata) SetRemoteAddress(rawAddress string) error {
host, port, err := net.SplitHostPort(rawAddress)
if err != nil {
return err
}
if ip, err := netip.ParseAddr(host); err != nil {
m.Host = host
m.DstIP = netip.Addr{}
} else {
m.Host = ""
m.DstIP = ip.Unmap()
}
m.DstPort = port
return nil
}