An Addr is a physical-layer address.
type Addr struct { HardwareAddr net.HardwareAddr }
func (a *Addr) Network() string
Network returns the address's network name, "packet".
func (a *Addr) String() string
String returns the string representation of an Addr.
Config contains options for a Conn.
type Config struct { // Filter is an optional assembled BPF filter which can be applied to the // Conn before bind(2) is called. // // The Conn.SetBPF method serves the same purpose once a Conn has already // been opened, but setting Filter applies the BPF filter before the Conn is // bound. This ensures that unexpected packets will not be captured before // the Conn is opened. Filter []bpf.RawInstruction }
A Conn is an Linux packet sockets (AF_PACKET) implementation of a net.PacketConn.
type Conn struct {
// contains filtered or unexported fields
}
func Listen(ifi *net.Interface, socketType Type, protocol int, cfg *Config) (*Conn, error)
Listen opens a packet sockets connection on the specified interface, using the given socket type and protocol values.
The socket type must be one of the Type constants: Raw or Datagram.
The Config specifies optional configuration for the Conn. A nil *Config applies the default configuration.
func (c *Conn) Close() error
Close closes the connection.
func (c *Conn) LocalAddr() net.Addr
LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it.
func (c *Conn) ReadFrom(b []byte) (int, net.Addr, error)
ReadFrom implements the net.PacketConn ReadFrom method.
func (c *Conn) SetBPF(filter []bpf.RawInstruction) error
SetBPF attaches an assembled BPF program to the Conn.
func (c *Conn) SetDeadline(t time.Time) error
SetDeadline implements the net.PacketConn SetDeadline method.
func (c *Conn) SetPromiscuous(enable bool) error
SetPromiscuous enables or disables promiscuous mode on the Conn, allowing it to receive traffic that is not addressed to the Conn's network interface.
func (c *Conn) SetReadDeadline(t time.Time) error
SetReadDeadline implements the net.PacketConn SetReadDeadline method.
func (c *Conn) SetWriteDeadline(t time.Time) error
SetWriteDeadline implements the net.PacketConn SetWriteDeadline method.
func (c *Conn) Stats() (*Stats, error)
Stats retrieves statistics about the Conn from the Linux kernel.
Note that calling Stats will reset the kernel's internal counters for this Conn. If you want to maintain cumulative statistics by polling Stats over time, you must do so in your calling code.
func (c *Conn) SyscallConn() (syscall.RawConn, error)
SyscallConn returns a raw network connection. This implements the syscall.Conn interface.
func (c *Conn) WriteTo(b []byte, addr net.Addr) (int, error)
WriteTo implements the net.PacketConn WriteTo method.
Stats contains statistics about a Conn reported by the Linux kernel.
type Stats struct { // The total number of packets received. Packets uint32 // The number of packets dropped. Drops uint32 // The total number of times that a receive queue is frozen. May be zero if // the Linux kernel is not new enough to support TPACKET_V3 statistics. FreezeQueueCount uint32 }
Type is a socket type used when creating a Conn with Listen.
type Type int
Possible Type values. Note that the zero value is not valid: callers must always specify one of Raw or Datagram when calling Listen.
const ( Raw Type Datagram )