ether

package module
v0.0.0-...-9fe60a3 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2016 License: BSD-3-Clause Imports: 5 Imported by: 1

README

GoDoc Build Status Go Report Card Coverage Status

ether

ether is a go package for sending and receiving ethernet frames.

Currently supported platform:

  • BPF based
    • OS X
    • FreeBSD
  • AF_PACKET based
    • Linux

Documentation

http://godoc.org/github.com/songgao/ether

TODO

  • in kernel packets filtering

License

BSD 3-Clause License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dev

type Dev interface {
	// Read reads a ethernet frame into *to. *to is expanded or re-allocated if
	// needed. As a result, a non-nil to pointed to a nil *to would work. If read
	// is successful, *to is resized to properly reflect the frame length.
	Read(to *ethernet.Frame) (err error)

	// Write writes a ethernet frame into the device. from should include
	// ethernet frame header as well as payload, but not ethernet CRC. See
	// ethernet.Frame document for constructing the frame. Caller needs to make
	// sure from has proper length. That is, the slice should be resized to
	// cover exact number of bytes of the frame.
	Write(from ethernet.Frame) error

	// Interface returns the *net.Interface that this Dev operates on.
	Interface() *net.Interface

	// Close closes the device fd. After calling this, this Dev cannot read from
	// or write into the device anymore. This means both Read() Write() should
	// fail on AF_PACKET based systems. On BPF based systems, Write() should
	// fail, and Read() can read until all frames in read buffer are consumed
	// before failing.
	Close() error
}

Dev represents a network interface.

func NewDev

func NewDev(ifce *net.Interface, frameFilter FrameFilter) (dev Dev, err error)

NewDev creates a new Dev that operates on ifce, with frameFilter used as a filter on incoming frames for Read(). If frameFilter is nil, all frames will be returned from Read().

type FrameFilter

type FrameFilter func(frame ethernet.Frame) bool

FrameFilter defines filter used for filtering incoming frames. It is used by Dev.Read() on each incoming frame. Return false to discard the frame, or true to take the frame.

Jump to

Keyboard shortcuts

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