Android: patch

This commit is contained in:
wwqgtxx 2023-10-23 16:52:19 +08:00
parent 5cca3569e9
commit a7040af346
2 changed files with 2 additions and 10 deletions

View File

@ -7,20 +7,10 @@ import (
"syscall" "syscall"
) )
type TunnelDialer func(context context.Context, network, address string) (net.Conn, error)
type SocketControl func(network, address string, conn syscall.RawConn) error type SocketControl func(network, address string, conn syscall.RawConn) error
var DefaultTunnelDialer TunnelDialer
var DefaultSocketHook SocketControl var DefaultSocketHook SocketControl
func DialTunnelContext(ctx context.Context, network, address string) (net.Conn, error) {
if dialer := DefaultTunnelDialer; dialer != nil {
return dialer(ctx, network, address)
}
return DialContext(ctx, network, address)
}
func dialContextHooked(ctx context.Context, network string, destination netip.Addr, port string) (net.Conn, error) { func dialContextHooked(ctx context.Context, network string, destination netip.Addr, port string) (net.Conn, error) {
dialer := &net.Dialer{ dialer := &net.Dialer{
Control: DefaultSocketHook, Control: DefaultSocketHook,

View File

@ -27,6 +27,8 @@ func HandleTcp(address string) (conn net.Conn, err error) {
metadata.Type = C.INNER metadata.Type = C.INNER
metadata.DNSMode = C.DNSNormal metadata.DNSMode = C.DNSNormal
metadata.Process = C.ClashName metadata.Process = C.ClashName
metadata.RawSrcAddr = conn1.RemoteAddr()
metadata.RawDstAddr = conn1.LocalAddr()
if h, port, err := net.SplitHostPort(address); err == nil { if h, port, err := net.SplitHostPort(address); err == nil {
if port, err := strconv.ParseUint(port, 10, 16); err == nil { if port, err := strconv.ParseUint(port, 10, 16); err == nil {
metadata.DstPort = uint16(port) metadata.DstPort = uint16(port)