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