l2pc

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFrame = errors.New("invalid frame")

Functions

This section is empty.

Types

type L2PacketConn

type L2PacketConn struct {
	// contains filtered or unexported fields
}

L2PacketConn adapts a net.PacketConn (UDP) to read/write L2 Ethernet frames.

func NewL2PacketConn

func NewL2PacketConn(pc batchpc.BatchPacketConn) (*L2PacketConn, error)

NewL2PacketConn creates a new L2PacketConn.

func (*L2PacketConn) Close

func (c *L2PacketConn) Close() error

func (*L2PacketConn) LocalMAC

func (c *L2PacketConn) LocalMAC() tcpip.LinkAddress

LocalMAC returns the locally-administered unicast MAC address used by this connection.

func (*L2PacketConn) ReadBatchFrames

func (c *L2PacketConn) ReadBatchFrames(msgs []batchpc.Message, flags int) (int, error)

ReadBatchFrames reads a batch of UDP payloads and emits fully-formed Ethernet frames into msgs[i].Buf (resizing the slice length to the frame size). msgs[i].Addr will be set to the remote *net.UDPAddr for convenience.

func (*L2PacketConn) ReadFrame

func (c *L2PacketConn) ReadFrame(dst []byte) (int, error)

ReadFrame reads from PacketConn and emits a full Ethernet frame into dst. The Ethernet dst MAC is our random local MAC; the src MAC is a stable random, locally-administered unicast MAC based on the remote IP.

func (*L2PacketConn) WriteBatchFrames

func (c *L2PacketConn) WriteBatchFrames(msgs []batchpc.Message, flags int) (int, error)

WriteBatchFrames consumes a batch of Ethernet frames (IPv4/IPv6 + UDP) and writes their UDP payloads to destinations extracted from each frame. On return, n is the number of frames successfully queued/written.

func (*L2PacketConn) WriteFrame

func (c *L2PacketConn) WriteFrame(frame []byte) error

WriteFrame consumes an Ethernet frame (IPv4/IPv6 + UDP) and writes the payload to the underlying PacketConn based on the frame’s dst IP:port.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL