network

package
v0.0.0-...-eacd88d Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2018 License: GPL-3.0 Imports: 5 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const (
	ETHERTYPE_IP   uint16 = 0x800
	ETHERTYPE_IPV6 uint16 = 0x86dd
	ETHERTYPE_ARP  uint16 = 0x806
	MAC_SIZE       int    = 6
)

Ethernet Header constants

View Source
const (
	IPPROTO_TCP    int = 6
	IPPROTO_UDP    int = 17
	IPPROTO_ICMP   int = 1
	IPPROTO_ICMPv6 int = 58
	IPV4_SIZE      int = 4
	IPV6_SIZE      int = 16
)

IP Header constants

Variables

View Source
var Log *logging.Logger

Functions

This section is empty.

Types

type EthHeader

type EthHeader struct {
	Hdest   []byte
	Hsource []byte
	Hproto  uint16
}

Ethernet

func NewEthHeader

func NewEthHeader(data []byte) *EthHeader

Constructor: Don't copy the data, just create a slice pointing to the data received. We want to make this operation as efficient as possible

func (*EthHeader) String

func (self *EthHeader) String() string

type IPAddress

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

func NewIPAddress

func NewIPAddress(data []byte) *IPAddress

func (*IPAddress) Compare

func (self *IPAddress) Compare(rhs *IPAddress) (int8, error)

*

  • @brief Compare the IPMasks. *
  • @param self Self
  • @param rhs Mac to compare *
  • @return 0 if self == rhs
  • 1 if self > rhs
  • -1 if self < rhs

func (*IPAddress) Increase

func (self *IPAddress) Increase() error

*

  • @brief Increase in one the IP. *
  • @return An error is returned if the maximum length of the
  • IP has been reached

func (*IPAddress) Raw

func (self *IPAddress) Raw() *net.IP

*

  • @return Return the IP as a stream of bytes

func (*IPAddress) String

func (self *IPAddress) String() string

*

  • @return String representing the IPAddress

type Mac

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

func NewMac

func NewMac(data []byte) *Mac

func (*Mac) Compare

func (self *Mac) Compare(rhs *Mac) int8

Compare every octet of both Macs to determine which if they are the same. The function returns 0 if both macs are equals, 1 if self > rhs and -1 if self < rhs

Example
mac1 := NewMac([]byte{0x00, 0x20, 0x40, 0x60, 0x80, 0xa0})
mac2 := NewMac([]byte{0x01, 0x20, 0x40, 0x60, 0x80, 0xa0})

if mac1.Compare(mac2) != 0 {
	fmt.Println("Macs are not equivalents")
}
Output:

Macs are not equivalents
Example (Second)
mac1 := NewMac([]byte{0x00, 0x20, 0x40, 0x60, 0x80, 0xa0})
mac2 := NewMac([]byte{0x00, 0x20, 0x40, 0x60, 0x80, 0xa0})

if mac1.Compare(mac2) == 0 {
	fmt.Println("Macs are equivalents")
}
Output:

func (*Mac) Increase

func (self *Mac) Increase() error

func (*Mac) String

func (self *Mac) String() string

type UdpHeader

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

UDP

Jump to

Keyboard shortcuts

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