mihomo/adapter/inbound/packet.go

23 lines
678 B
Go
Raw Normal View History

package inbound
import (
2023-11-03 21:01:45 +08:00
C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/transport/socks5"
)
// NewPacket is PacketAdapter generator
2023-10-11 10:55:12 +08:00
func NewPacket(target socks5.Addr, packet C.UDPPacket, source C.Type, additions ...Addition) (C.UDPPacket, *C.Metadata) {
metadata := parseSocksAddr(target)
2020-01-31 14:43:54 +08:00
metadata.NetWork = C.UDP
metadata.Type = source
metadata.RawSrcAddr = packet.LocalAddr()
metadata.RawDstAddr = metadata.UDPAddr()
2023-10-11 22:54:19 +08:00
ApplyAdditions(metadata, WithSrcAddr(packet.LocalAddr()))
2023-10-10 19:43:26 +08:00
if p, ok := packet.(C.UDPPacketInAddr); ok {
2023-10-11 22:54:19 +08:00
ApplyAdditions(metadata, WithInAddr(p.InAddr()))
}
2023-10-11 22:54:19 +08:00
ApplyAdditions(metadata, additions...)
2023-10-11 10:55:12 +08:00
return packet, metadata
2022-12-04 13:37:14 +08:00
}