Documentation ¶
Index ¶
Constants ¶
const ( EtherAddrLen = 6 IPv4AddrLen = 4 IPv6AddrLen = 16 )
Length of addresses.
const ( IPV4Number = 0x0800 ARPNumber = 0x0806 VLANNumber = 0x8100 MPLSNumber = 0x8847 IPV6Number = 0x86dd SwapIPV4Number = 0x0008 SwapARPNumber = 0x0608 SwapVLANNumber = 0x0081 SwapMPLSNumber = 0x4788 SwapIPV6Number = 0xdd86 )
Supported EtherType for L2
const ( ICMPNumber = 0x01 IPNumber = 0x04 TCPNumber = 0x06 UDPNumber = 0x11 GRENumber = 0x2f ICMPv6Number = 0x3a NoNextHeader = 0x3b )
Supported L4 types
const ( ICMPTypeEchoRequest uint8 = 8 ICMPTypeEchoResponse uint8 = 0 ICMPv6TypeEchoRequest uint8 = 128 ICMPv6TypeEchoResponse uint8 = 129 ICMPv6NeighborSolicitation uint8 = 135 ICMPv6NeighborAdvertisement uint8 = 136 )
Supported ICMP Types
const ( EtherLen = 14 VLANLen = 4 MPLSLen = 4 IPv4MinLen = 20 IPv6Len = 40 ICMPLen = 8 TCPMinLen = 20 UDPLen = 8 ARPLen = 28 GTPMinLen = 8 GRELen = 4 )
These constants keep length of supported headers in bytes.
IPv6Len - minimum length of IPv6 header in bytes. It can be higher and it is not determined inside packet. Only default minimum size is used.
IPv4MinLen and TCPMinLen are used only in packet generation functions.
In parsing we take actual length of TCP header from DataOff field and length of IPv4 take from Ihl field.
const ( TCPMinDataOffset = 0x50 // minimal tcp data offset IPv4VersionIhl = 0x45 // IPv4, IHL = 5 (min header len) IPv6VtcFlow = 0x60 // IPv6 version )
const ( TCPFlagFin = 0x01 TCPFlagSyn = 0x02 TCPFlagRst = 0x04 TCPFlagPsh = 0x08 TCPFlagAck = 0x10 TCPFlagUrg = 0x20 TCPFlagEce = 0x40 TCPFlagCwr = 0x80 )
Constants for valuues of TCP flags.
const MaxLength = math.MaxInt32
Max array length for type conversions
Variables ¶
This section is empty.
Functions ¶
func IPv4ArrayToString ¶
func IPv4ArrayToString(addr [IPv4AddrLen]uint8) string
func IPv4ToBytes ¶
func IPv4ToBytes(v IPv4Address) [IPv4AddrLen]byte
IPv4ToBytes converts four element address to IPv4Address representation
Types ¶
type IPv4Address ¶
type IPv4Address uint32
func ArrayToIPv4 ¶
func ArrayToIPv4(a [IPv4AddrLen]byte) IPv4Address
ArrayToIPv4 converts four element array to IPv4Address representation
func BytesToIPv4 ¶
func BytesToIPv4(a byte, b byte, c byte, d byte) IPv4Address
BytesToIPv4 converts four element address to IPv4Address representation
func SliceToIPv4 ¶
func SliceToIPv4(s []byte) IPv4Address
SliceToIPv4 converts four element slice to IPv4Address representation
func (IPv4Address) String ¶
func (addr IPv4Address) String() string
func (*IPv4Address) UnmarshalJSON ¶
func (out *IPv4Address) UnmarshalJSON(b []byte) error
UnmarshalJSON parses IPv4 address.
type IPv4Subnet ¶
type IPv4Subnet struct { Addr IPv4Address Mask IPv4Address }
func (*IPv4Subnet) CheckIPv4AddressWithinSubnet ¶
func (sn *IPv4Subnet) CheckIPv4AddressWithinSubnet(addr IPv4Address) bool
CheckIPv4AddressWithinSubnet returns true if IPv4 addr is inside of specified subnet.
func (*IPv4Subnet) String ¶
func (sn *IPv4Subnet) String() string
func (*IPv4Subnet) UnmarshalJSON ¶
func (out *IPv4Subnet) UnmarshalJSON(b []byte) error
UnmarshalJSON parses ipv 4 subnet details.
type IPv6Address ¶
type IPv6Address [IPv6AddrLen]uint8
func (IPv6Address) String ¶
func (addr IPv6Address) String() string
func (*IPv6Address) UnmarshalJSON ¶
func (out *IPv6Address) UnmarshalJSON(b []byte) error
UnmarshalJSON parses IPv6 address.
type IPv6Subnet ¶
type IPv6Subnet struct { Addr IPv6Address Mask IPv6Address }
func (*IPv6Subnet) AndIPv6Mask ¶
func (sn *IPv6Subnet) AndIPv6Mask(addr IPv6Address) IPv6Address
AndIPv6Mask performs bit AND operation for IPv6 address and mask.
func (*IPv6Subnet) CheckIPv6AddressWithinSubnet ¶
func (sn *IPv6Subnet) CheckIPv6AddressWithinSubnet(addr IPv6Address) bool
CheckIPv6AddressWithinSubnet returns true if IPv6 addr is inside of specified subnet.
func (*IPv6Subnet) String ¶
func (sn *IPv6Subnet) String() string
func (*IPv6Subnet) UnmarshalJSON ¶
func (out *IPv6Subnet) UnmarshalJSON(b []byte) error
UnmarshalJSON parses ipv 6 subnet details.
type MACAddress ¶
type MACAddress [EtherAddrLen]uint8
func StringToMACAddress ¶ added in v0.8.1
func StringToMACAddress(str string) (MACAddress, error)
StringToMACAddress parses a string which contains a MAC address.
func (MACAddress) String ¶
func (mac MACAddress) String() string
MACToString return MAC address like string
func (*MACAddress) UnmarshalJSON ¶ added in v0.8.1
func (out *MACAddress) UnmarshalJSON(b []byte) error
UnmarshalJSON parses JSON element which contains string which contains MAC address.