github.com/yaling888/clash@v1.53.0/adapter/inbound/mitm.go (about) 1 package inbound 2 3 import ( 4 "net" 5 "net/netip" 6 7 C "github.com/yaling888/clash/constant" 8 "github.com/yaling888/clash/context" 9 "github.com/yaling888/clash/transport/socks5" 10 ) 11 12 // NewMitm receive mitm request and return MitmContext 13 func NewMitm(target socks5.Addr, source net.Addr, originTarget net.Addr, userAgent string, specialProxy string, conn net.Conn) *context.ConnContext { 14 metadata := parseSocksAddr(target) 15 metadata.NetWork = C.TCP 16 metadata.Type = C.MITM 17 metadata.UserAgent = userAgent 18 metadata.SpecialProxy = specialProxy 19 20 if ip, port, err := parseAddr(source); err == nil { 21 metadata.SrcIP = ip 22 metadata.SrcPort = C.Port(port) 23 } 24 if ip, port, err := parseAddr(originTarget); err == nil { 25 metadata.OriginDst = netip.AddrPortFrom(ip, uint16(port)) 26 } 27 return context.NewConnContext(conn, metadata) 28 }