Documentation ¶
Index ¶
- Constants
- type Addr
- type Config
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) ReadFrom(b []byte) (int, net.Addr, error)
- func (c *Conn) RecvRxTimestamps(b []byte) (int, net.Addr, SocketTimestamps, error)
- func (c *Conn) RecvTxTimestamps(b []byte) (int, net.Addr, SocketTimestamps, error)
- func (c *Conn) SetBPF(filter []bpf.RawInstruction) error
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Stats() (*Stats, error)
- func (c *Conn) WriteTo(b []byte, addr net.Addr) (int, error)
- type SocketTimestamps
- type Stats
Constants ¶
const ( // SocketOptTimestamping is an alias for unix.SO_TIMESTAMPING SocketOptTimestamping = 0x25 // MsgErrQueue is an alias for unix.MSG_ERRQUEUE MsgErrQueue = 0x2000 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // DualConn creates separate send and recv connections to minimize contention // on a single file descriptor. Enable this option if you're sending packets // at a high rate. Calling methods on Conn will transparently use the correct // underlying socket. DualConn bool // Filter will be applied to the socket before bind is called to ensure // no packets will come through before the connection is opened. Filter []bpf.RawInstruction }
Config
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn implements net.PacketConn and uses AF_PACKET under the hood
func (*Conn) RecvRxTimestamps ¶
RecvRxTimestamps blocks and listens on the underlying socket's Rx queue for incoming packets while also returning the Rx timestamps for that packet. This can be used instead of ReadFrom to get SocketTimestamps returned along with the packet data.
func (*Conn) RecvTxTimestamps ¶
RecvTxTimestamps blocks and listens on the underlying socket's error queue for outgoing Tx timestamp information and returns the original packet plus the timestamp information.
func (*Conn) SetBPF ¶
func (c *Conn) SetBPF(filter []bpf.RawInstruction) error
SetBPF applies the BPF program filter to the socket
func (*Conn) SetDeadline ¶
SetDeadline implements net.PacketConn SetDeadline
func (*Conn) SetReadDeadline ¶
SetReadDeadline implements net.PacketConn SetReadDeadline
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline implements net.PacketConn Close
type SocketTimestamps ¶
SocketTimestamps represet the timestamps generated by the NIC (Hardware) and the Kernel (Software) that is parse from the control message.
func ParseSocketTimestamps ¶
func ParseSocketTimestamps(msg unix.SocketControlMessage) (SocketTimestamps, error)
ParseSocketTimestamps parses the timestamp information from the control message it will also convert Unix epoch times to Go's zero value time to be able to use .IsZero() on timestamps that have a default value or are not available. https://www.kernel.org/doc/html/v5.14/networking/timestamping.html#scm-timestamping-records
type Stats ¶
type Stats struct { // Packets are the total number of packets received Packets uint32 // Drops are the number of packets dropped Drops uint32 // FreezeQueueCount is the total number of times that a receive queue is // frozen. May be zero if the kernel is not new enough to support TPACKET_V3 FreezeQueueCount uint32 }
Stats are the statistics obtained from the kernel.