ip

package
Version: v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IPPROTO_IP   = 0
	IPPROTO_ICMP = 1

	IPPROTO_TCP = 6
	IPPROTO_UDP = 17

	IPPROTO_RAW = 255
)
View Source
const ICMP_DEST_UNREACH = 3
View Source
const ICMP_NET_UNREACH = 0
View Source
const IPVERSION = 4
View Source
const MAX_ICMPHEADER = 8
View Source
const MAX_IP6HEADER = 40
View Source
const MAX_IPHEADER = 20
View Source
const MAX_IPOPTLEN = 40

Variables

View Source
var NativeEndian binary.ByteOrder

NativeEndian is the ByteOrder of the current system.

Functions

func CheckSum

func CheckSum(body []uint32) uint16

func ICMPUnreachable

func ICMPUnreachable(saddr IP4, off_iph *IP4Header, offender []byte) ([]byte, error)

func IP4HeaderCoder

func IP4HeaderCoder(iphdr *IP4Header) []byte

func IP6HeaderCoder

func IP6HeaderCoder(iphdr *IP6Header) []byte

func InterfaceAddsGet

func InterfaceAddsGet(iface *net.Interface) ([]net.IP, error)

func InterfaceByAddr

func InterfaceByAddr(addr string) (*net.Interface, error)

func InterfaceByName

func InterfaceByName(ifname string) (*net.Interface, error)

func IsIPString

func IsIPString(ip string) bool

func IsIPv4

func IsIPv4(ip net.IP) bool

func NativelyLittle

func NativelyLittle() bool

func ParseIP6

func ParseIP6(s string) (net.IP, error)

Types

type ICMPHeader

type ICMPHeader struct {
	Type     uint8
	Code     uint8
	Check    uint16
	Reserved [4]byte
}

func (*ICMPHeader) Coder

func (icmp *ICMPHeader) Coder(body []byte)

func (*ICMPHeader) MakeCheckSum

func (icmp *ICMPHeader) MakeCheckSum(data []byte)

type ICMPPacket

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

func (*ICMPPacket) Coder

func (pkt *ICMPPacket) Coder(data []byte) []byte

type IP4

type IP4 uint32

func FromBytesIP4

func FromBytesIP4(ip []byte) IP4

func FromIP

func FromIP(ip net.IP) IP4

func MustParseIP4

func MustParseIP4(s string) IP4

func ParseIP4

func ParseIP4(s string) (IP4, error)

func (IP4) MarshalJSON

func (ip IP4) MarshalJSON() ([]byte, error)

MarshalJSON: json.Marshaler impl

func (IP4) NetworkOrder

func (ip IP4) NetworkOrder() uint32

func (IP4) Octets

func (ip IP4) Octets() (a, b, c, d byte)

func (IP4) String

func (ip IP4) String() string

func (IP4) StringSep

func (ip IP4) StringSep(sep string) string

func (IP4) ToIP

func (ip IP4) ToIP() net.IP

func (*IP4) UnmarshalJSON

func (ip *IP4) UnmarshalJSON(j []byte) error

UnmarshalJSON: json.Unmarshaler impl

type IP4Header

type IP4Header struct {
	Version uint8
	HeadLen uint8

	Tos     uint8
	TotLen  uint16
	Id      uint16
	FragOff uint16

	TTL      uint8
	Protocal uint8

	Check uint16
	SAddr IP4
	DAddr IP4
}

func IP4HeaderDecoder

func IP4HeaderDecoder(buff []byte) *IP4Header

func (*IP4Header) CheckSum

func (iphdr *IP4Header) CheckSum() bool

func (*IP4Header) Coder

func (iphdr *IP4Header) Coder(buff []byte)

func (*IP4Header) Decoder

func (iphdr *IP4Header) Decoder(buff []byte) *IP4Header

func (*IP4Header) DecrementTTL

func (iphdr *IP4Header) DecrementTTL() error

func (*IP4Header) MakeCheckSum

func (iphdr *IP4Header) MakeCheckSum()

func (*IP4Header) String

func (iphdr *IP4Header) String() string

type IP4Net

type IP4Net struct {
	IP        IP4
	PrefixLen uint
}

similar to net.IPNet but has uint based representation

func FromIPNet

func FromIPNet(n *net.IPNet) IP4Net

func NewIP4Net

func NewIP4Net(addr string, len uint) (*IP4Net, error)

func (IP4Net) Contains

func (n IP4Net) Contains(ip IP4) bool

func (IP4Net) Empty

func (n IP4Net) Empty() bool

func (IP4Net) Equal

func (n IP4Net) Equal(other IP4Net) bool

func (IP4Net) MarshalJSON

func (n IP4Net) MarshalJSON() ([]byte, error)

MarshalJSON: json.Marshaler impl

func (IP4Net) Mask

func (n IP4Net) Mask() uint32

func (IP4Net) MaskToIP

func (n IP4Net) MaskToIP() net.IP

func (IP4Net) Network

func (n IP4Net) Network() IP4Net

func (IP4Net) NetworkToIP

func (n IP4Net) NetworkToIP() net.IP

func (IP4Net) Next

func (n IP4Net) Next() IP4Net

func (IP4Net) Overlaps

func (n IP4Net) Overlaps(other IP4Net) bool

func (IP4Net) String

func (n IP4Net) String() string

func (IP4Net) StringSep

func (n IP4Net) StringSep(octetSep, prefixSep string) string

func (IP4Net) ToIPNet

func (n IP4Net) ToIPNet() *net.IPNet

func (*IP4Net) UnmarshalJSON

func (n *IP4Net) UnmarshalJSON(j []byte) error

UnmarshalJSON: json.Unmarshaler impl

type IP6

type IP6 []byte

func (IP6) MarshalJSON

func (ip IP6) MarshalJSON() ([]byte, error)

MarshalJSON: json.Marshaler impl

func (IP6) String

func (ip IP6) String() string

func (IP6) UnmarshalJSON

func (ip IP6) UnmarshalJSON(j []byte) error

UnmarshalJSON: json.Unmarshaler impl

type IP6Header

type IP6Header struct {
	Version  uint8
	Priority uint8

	FlowLabel uint32
	PlayLoad  uint16

	NextHdr  uint8
	HopLimit uint8

	SAddr IP6
	DAddr IP6
}

func IP6HeaderDecoder

func IP6HeaderDecoder(buff []byte) *IP6Header

func (*IP6Header) Coder

func (iphdr *IP6Header) Coder(buff []byte)

func (*IP6Header) Decoder

func (iphdr *IP6Header) Decoder(buff []byte) *IP6Header

func (*IP6Header) String

func (iphdr *IP6Header) String() string

type IPType

type IPType int
const (
	Ping IPType
	IPv4
	IPv6
	IPCtrl
)

func IPHeaderType

func IPHeaderType(buff byte) IPType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL