Documentation ¶
Overview ¶
Package sniffer provides the implementation of data-link layer endpoints that wrap another endpoint and logs inbound and outbound packets.
Sniffer endpoints can be used in the networking stack by calling New(eID) to create a new endpoint, where eID is the ID of the endpoint being wrapped, and then passing it as an argument to Stack.CreateNIC().
Index ¶
- Constants
- Variables
- func LogPacket(prefix string, dir Direction, protocol tcpip.NetworkProtocolNumber, ...)
- func New(lower stack.LinkEndpoint) stack.LinkEndpoint
- func NewWithPrefix(lower stack.LinkEndpoint, logPrefix string) stack.LinkEndpoint
- func NewWithWriter(lower stack.LinkEndpoint, writer io.Writer, snapLen uint32) (stack.LinkEndpoint, error)
- type Direction
Constants ¶
const ( // DirectionSend indicates a sent packet. DirectionSend = iota // DirectionRecv indicates a received packet. DirectionRecv )
Variables ¶
var LogPackets atomicbitops.Uint32 = atomicbitops.FromUint32(1)
LogPackets is a flag used to enable or disable packet logging via the log package. Valid values are 0 or 1.
var LogPacketsToPCAP atomicbitops.Uint32 = atomicbitops.FromUint32(1)
LogPacketsToPCAP is a flag used to enable or disable logging packets to a pcap writer. Valid values are 0 or 1. A writer must have been specified when the sniffer was created for this flag to have effect.
Functions ¶
func LogPacket ¶
func LogPacket(prefix string, dir Direction, protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr)
LogPacket logs a packet to stdout.
func New ¶
func New(lower stack.LinkEndpoint) stack.LinkEndpoint
New creates a new sniffer link-layer endpoint. It wraps around another endpoint and logs packets and they traverse the endpoint.
func NewWithPrefix ¶
func NewWithPrefix(lower stack.LinkEndpoint, logPrefix string) stack.LinkEndpoint
NewWithPrefix creates a new sniffer link-layer endpoint. It wraps around another endpoint and logs packets prefixed with logPrefix as they traverse the endpoint.
logPrefix is prepended to the log line without any separators. E.g. logPrefix = "NIC:en0/" will produce log lines like "NIC:en0/send udp [...]".
func NewWithWriter ¶
func NewWithWriter(lower stack.LinkEndpoint, writer io.Writer, snapLen uint32) (stack.LinkEndpoint, error)
NewWithWriter creates a new sniffer link-layer endpoint. It wraps around another endpoint and logs packets as they traverse the endpoint.
Each packet is written to writer in the pcap format in a single Write call without synchronization. A sniffer created with this function will not emit packets using the standard log package.
snapLen is the maximum amount of a packet to be saved. Packets with a length less than or equal to snapLen will be saved in their entirety. Longer packets will be truncated to snapLen.