mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-16 07:20:58 +00:00
chore: better addr parsing
This commit is contained in:
parent
09c7ee0d12
commit
9e8f4ada47
4 changed files with 13 additions and 10 deletions
|
@ -196,7 +196,7 @@ func (l *Listener) HandleConn(conn net.Conn, tunnel C.Tunnel, additions ...inbou
|
|||
ctx := sing.WithAdditions(context.TODO(), additions...)
|
||||
err := l.service.NewConnection(ctx, conn, M.Metadata{
|
||||
Protocol: "shadowsocks",
|
||||
Source: M.ParseSocksaddr(conn.RemoteAddr().String()),
|
||||
Source: M.SocksaddrFromNet(conn.RemoteAddr()),
|
||||
})
|
||||
if err != nil {
|
||||
_ = conn.Close()
|
||||
|
|
|
@ -201,7 +201,7 @@ func (l *Listener) HandleConn(conn net.Conn, tunnel C.Tunnel, additions ...inbou
|
|||
ctx := sing.WithAdditions(context.TODO(), additions...)
|
||||
err := l.service.NewConnection(ctx, conn, metadata.Metadata{
|
||||
Protocol: "vless",
|
||||
Source: metadata.ParseSocksaddr(conn.RemoteAddr().String()),
|
||||
Source: metadata.SocksaddrFromNet(conn.RemoteAddr()),
|
||||
})
|
||||
if err != nil {
|
||||
_ = conn.Close()
|
||||
|
|
|
@ -187,7 +187,7 @@ func (l *Listener) HandleConn(conn net.Conn, tunnel C.Tunnel, additions ...inbou
|
|||
ctx := sing.WithAdditions(context.TODO(), additions...)
|
||||
err := l.service.NewConnection(ctx, conn, metadata.Metadata{
|
||||
Protocol: "vmess",
|
||||
Source: metadata.ParseSocksaddr(conn.RemoteAddr().String()),
|
||||
Source: metadata.SocksaddrFromNet(conn.RemoteAddr()),
|
||||
})
|
||||
if err != nil {
|
||||
_ = conn.Close()
|
||||
|
|
|
@ -189,7 +189,7 @@ func ServerHandshake(rw net.Conn, authenticator auth.Authenticator) (addr Addr,
|
|||
switch command {
|
||||
case CmdConnect, CmdUDPAssociate:
|
||||
// Acquire server listened address info
|
||||
localAddr := ParseAddr(rw.LocalAddr().String())
|
||||
localAddr := ParseAddrToSocksAddr(rw.LocalAddr())
|
||||
if localAddr == nil {
|
||||
err = ErrAddressNotSupported
|
||||
} else {
|
||||
|
@ -414,12 +414,15 @@ func ParseAddr(s string) Addr {
|
|||
func ParseAddrToSocksAddr(addr net.Addr) Addr {
|
||||
var hostip net.IP
|
||||
var port int
|
||||
if udpaddr, ok := addr.(*net.UDPAddr); ok {
|
||||
hostip = udpaddr.IP
|
||||
port = udpaddr.Port
|
||||
} else if tcpaddr, ok := addr.(*net.TCPAddr); ok {
|
||||
hostip = tcpaddr.IP
|
||||
port = tcpaddr.Port
|
||||
switch addr := addr.(type) {
|
||||
case *net.UDPAddr:
|
||||
hostip = addr.IP
|
||||
port = addr.Port
|
||||
case *net.TCPAddr:
|
||||
hostip = addr.IP
|
||||
port = addr.Port
|
||||
case nil:
|
||||
return nil
|
||||
}
|
||||
|
||||
// fallback parse
|
||||
|
|
Loading…
Add table
Reference in a new issue