Clash.Meta/listener/tunnel/packet.go

37 lines
633 B
Go
Raw Normal View History

2022-11-18 22:57:33 +08:00
package tunnel
import (
"net"
2023-11-03 21:01:45 +08:00
"github.com/metacubex/mihomo/common/pool"
2022-11-18 22:57:33 +08:00
)
type packet struct {
pc net.PacketConn
rAddr net.Addr
payload []byte
}
func (c *packet) Data() []byte {
return c.payload
}
// WriteBack write UDP packet with source(ip, port) = `addr`
func (c *packet) WriteBack(b []byte, addr net.Addr) (n int, err error) {
return c.pc.WriteTo(b, c.rAddr)
}
// LocalAddr returns the source IP/Port of UDP Packet
func (c *packet) LocalAddr() net.Addr {
return c.rAddr
}
func (c *packet) Drop() {
_ = pool.Put(c.payload)
c.payload = nil
2022-11-18 22:57:33 +08:00
}
func (c *packet) InAddr() net.Addr {
return c.pc.LocalAddr()
}