github.com/metacubex/mihomo@v1.18.5/adapter/inbound/packet.go (about)

     1  package inbound
     2  
     3  import (
     4  	C "github.com/metacubex/mihomo/constant"
     5  	"github.com/metacubex/mihomo/transport/socks5"
     6  )
     7  
     8  // NewPacket is PacketAdapter generator
     9  func NewPacket(target socks5.Addr, packet C.UDPPacket, source C.Type, additions ...Addition) (C.UDPPacket, *C.Metadata) {
    10  	metadata := parseSocksAddr(target)
    11  	metadata.NetWork = C.UDP
    12  	metadata.Type = source
    13  	metadata.RawSrcAddr = packet.LocalAddr()
    14  	metadata.RawDstAddr = metadata.UDPAddr()
    15  	ApplyAdditions(metadata, WithSrcAddr(packet.LocalAddr()))
    16  	if p, ok := packet.(C.UDPPacketInAddr); ok {
    17  		ApplyAdditions(metadata, WithInAddr(p.InAddr()))
    18  	}
    19  	ApplyAdditions(metadata, additions...)
    20  
    21  	return packet, metadata
    22  }