raw

package module
v0.0.0-...-e58a59e Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2017 License: MIT Imports: 10 Imported by: 0

README

raw Build Status GoDoc Go Report Card

Package raw enables reading and writing data at the device driver level for a network interface. MIT Licensed.

For more information about using raw sockets with Ethernet frames in Go, check out my blog post: Network Protocol Breakdown: Ethernet and Go.

Portions of this code are taken from the Go standard library. The Go standard library is Copyright (c) 2012 The Go Authors. All rights reserved. The Go license can be found at https://golang.org/LICENSE.

Documentation

Overview

Package raw enables reading and writing data at the device driver level for a network interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotImplemented is returned when certain functionality is not yet
	// implemented for the host operating system.
	ErrNotImplemented = errors.New("raw: not implemented")
)

Functions

This section is empty.

Types

type Addr

type Addr struct {
	HardwareAddr net.HardwareAddr
}

Addr is a network address which can be used to contact other machines, using their hardware addresses.

func (*Addr) Network

func (a *Addr) Network() string

Network returns the address's network name, "raw".

func (*Addr) String

func (a *Addr) String() string

String returns the address's hardware address.

type Conn

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

Conn is an implementation of the net.PacketConn interface which can send and receive data at the network interface device driver level.

func ListenPacket

func ListenPacket(ifi *net.Interface, proto Protocol) (*Conn, error)

ListenPacket creates a net.PacketConn which can be used to send and receive data at the network interface device driver level.

ifi specifies the network interface which will be used to send and receive data. proto specifies the protocol which should be captured and transmitted. proto, if needed, is automatically converted to network byte order (big endian), akin to the htons() function in C.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*Conn) ReadFrom

func (c *Conn) ReadFrom(b []byte) (int, net.Addr, error)

ReadFrom implements the net.PacketConn ReadFrom method.

func (*Conn) ReadMsg

func (c *Conn) ReadMsg(b, oob []byte) (int, int, int, net.Addr, error)

func (*Conn) SetBPF

func (c *Conn) SetBPF(filter []bpf.RawInstruction) error

SetBPF attaches an assembled BPF program to the connection.

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

SetDeadline implements the net.PacketConn SetDeadline method.

func (*Conn) SetPacketAuxdata

func (c *Conn) SetPacketAuxdata() error

func (*Conn) SetPromiscuous

func (c *Conn) SetPromiscuous(b bool) error

SetPromiscuous enables or disables promiscuous mode on the interface, allowing it to receive traffic that is not addressed to the interface.

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline implements the net.PacketConn SetReadDeadline method.

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the net.PacketConn SetWriteDeadline method.

func (*Conn) WriteTo

func (c *Conn) WriteTo(b []byte, addr net.Addr) (int, error)

WriteTo implements the net.PacketConn WriteTo method.

type Protocol

type Protocol uint16

A Protocol is a network protocol constant which identifies the type of traffic a raw socket should send and receive.

const (
	// ProtocolAoE specifies the ATA over Ethernet protocol (AoEr11).
	ProtocolAoE Protocol = 0x88a2

	// ProtocolARP specifies the Address Resolution Protocol (RFC 826).
	ProtocolARP Protocol = 0x0806

	// ProtocolWoL specifies the Wake-on-LAN protocol.
	ProtocolWoL Protocol = 0x0842
)

Jump to

Keyboard shortcuts

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