Documentation
¶
Index ¶
- Constants
- type EtherSocket
- func (es *EtherSocket) GetGatewayHWAddr() net.HardwareAddr
- func (es *EtherSocket) GetHWAddr() net.HardwareAddr
- func (es *EtherSocket) MTU() int
- func (es *EtherSocket) Name() string
- func (es *EtherSocket) Read() ([]byte, error)
- func (es *EtherSocket) ReadFrame() (*Frame, error)
- func (es *EtherSocket) Write(data []byte) error
- func (es *EtherSocket) WriteFrame(f *Frame) error
- func (es *EtherSocket) WriteTo(to net.HardwareAddr, data []byte) error
- type Frame
- type VLAN
Constants ¶
View Source
const ( EtherTypeIPv4 = 0x0800 EtherTypeARP = 0x0806 EtherTypeIPv6 = 0x86DD EtherTypeVLAN = 0x8100 EtherTypeQinQ = 0x88a8 )
Most popular ether types
View Source
const VIDMax = 0xFFF
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EtherSocket ¶
type EtherSocket struct {
// contains filtered or unexported fields
}
func NewEtherSocket ¶
func NewEtherSocket(sock *socket.Interface) (*EtherSocket, error)
NewEtherSocket create ether socket over device
func (*EtherSocket) GetGatewayHWAddr ¶
func (es *EtherSocket) GetGatewayHWAddr() net.HardwareAddr
GetGatewayHWAddr returns mac address of device's default gateway
func (*EtherSocket) GetHWAddr ¶
func (es *EtherSocket) GetHWAddr() net.HardwareAddr
GetHWAddr returns mac address of device
func (*EtherSocket) MTU ¶
func (es *EtherSocket) MTU() int
MTU returns maximum transmission unit of device
func (*EtherSocket) Read ¶
func (es *EtherSocket) Read() ([]byte, error)
Read returns payload of ethernet frame
func (*EtherSocket) ReadFrame ¶
func (es *EtherSocket) ReadFrame() (*Frame, error)
ReadFrame returns full ethernet frame with payload
func (*EtherSocket) Write ¶
func (es *EtherSocket) Write(data []byte) error
WriteTo writes data to socket, destination is default gateway. Use Ether Type IPv4
func (*EtherSocket) WriteFrame ¶
func (es *EtherSocket) WriteFrame(f *Frame) error
func (*EtherSocket) WriteTo ¶
func (es *EtherSocket) WriteTo(to net.HardwareAddr, data []byte) error
WriteTo writes data to socket, with certain destination mac addr. Use Ether Type IPv4
type Frame ¶
type Frame struct {
// Destination MAC address
DestHarwAddr net.HardwareAddr
// Source MAC address
SrcHarwAddr net.HardwareAddr
// IEEE 802.1Q (VLAN) header
// IEEE 802.1Q is the networking standard that supports virtual local area networking (VLANs)
// on an IEEE 802.3 Ethernet network.
VLAN *VLAN
// IEEE 802.1ad (VLAN) header
// QinQ frame is a frame that has two VLAN 802.1Q headers (i.e. it is double-tagged).
ServiceVLAN *VLAN
// EtherType is a two-octet field in an Ethernet frame.
// It is used to indicate which protocol is encapsulated in the payload of the frame
// https://en.wikipedia.org/wiki/EtherType
EtherType uint16
// Data of frame
Payload []byte
}
Ethernet 802.3 frame
type VLAN ¶
type VLAN struct {
// Different PCP values can be used to prioritize different classes of traffic
Priority uint8
// This field was formerly designated Canonical Format Indicator (CFI)
// with a value of 0 indicating a MAC address in canonical format.
// It is always set to zero for Ethernet.
DropEligible bool
// Field specifying the VLAN to which the frame belongs.
ID uint16
}
IEEE 802.1Q vlan structure
Click to show internal directories.
Click to hide internal directories.