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