mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
93ea037230
Co-authored-by: Dreamacro <Dreamacro@vip.qq.com>
34 lines
789 B
Go
34 lines
789 B
Go
package inbound
|
|
|
|
import (
|
|
"github.com/Dreamacro/clash/component/socks5"
|
|
C "github.com/Dreamacro/clash/constant"
|
|
)
|
|
|
|
// PacketAdapter is a UDP Packet adapter for socks/redir/tun
|
|
type PacketAdapter struct {
|
|
C.UDPPacket
|
|
metadata *C.Metadata
|
|
}
|
|
|
|
// Metadata returns destination metadata
|
|
func (s *PacketAdapter) Metadata() *C.Metadata {
|
|
return s.metadata
|
|
}
|
|
|
|
// NewPacket is PacketAdapter generator
|
|
func NewPacket(target socks5.Addr, packet C.UDPPacket, source C.Type, netType C.NetWork) *PacketAdapter {
|
|
metadata := parseSocksAddr(target)
|
|
metadata.NetWork = netType
|
|
metadata.Type = source
|
|
if ip, port, err := parseAddr(packet.LocalAddr().String()); err == nil {
|
|
metadata.SrcIP = ip
|
|
metadata.SrcPort = port
|
|
}
|
|
|
|
return &PacketAdapter{
|
|
UDPPacket: packet,
|
|
metadata: metadata,
|
|
}
|
|
}
|