ipv4

package
v0.0.0-...-e4d881b Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IPProtoICMP = 1
	IPProtoUDP  = 17
	IPProtoTCP  = 6
)

IPv4 Protocols

View Source
const (
	IPMTU = 1500
)

The MTU, or maximum transmission unit

View Source
const IPv4AddressLength = 4

The length of an IPv4 Address

Variables

View Source
var (
	IPAll     *Address
	IPAllHash Hash
)

Utilities for binding to all IP addresses

Functions

func CalcTransportChecksum

func CalcTransportChecksum(header []byte, srcIP, dstIP *Address, headerLen uint16, proto uint8) uint16

CalcTransportChecksum calculates a checksum of a transport layer protocol (TCP or UDP)

func Checksum

func Checksum(data []byte) uint16

Checksum computes the 16-bit one's complement checksum of the given data. Done according to the procedure outlined in RFC 1071 (https://tools.ietf.org/html/rfc1071).

func VerifyTransportChecksum

func VerifyTransportChecksum(header []byte, srcIP, dstIP *Address, headerLen uint16, proto uint8) bool

VerifyTransportChecksum verifies a given checksum from a transport layer protocol (TCP or UDP)

Types

type Address

type Address struct {
	IP []byte
}

Address represents an IP address

var (
	LoopbackIPAddress *Address
	ExternalIPAddress *Address
)

The stack's IP addresses, which are used when sending data

func MakeIP

func MakeIP(ip string) *Address

MakeIP converts a string into an Address

func (*Address) ARPEqual

func (ip *Address) ARPEqual(other arp.ProtocolAddress) bool

func (*Address) Equal

func (ip *Address) Equal(other *Address) bool

func (*Address) Hash

func (ip *Address) Hash() Hash

Hash converts an IP Address into a uint32 for hashing purposes

func (*Address) Len

func (ip *Address) Len() uint8

Len returns the length of a marshaled IP address

func (*Address) Marshal

func (ip *Address) Marshal() ([]byte, error)

Marshal turns an IP Address into a slice of bytes

type Hash

type Hash uint32

Hash is the type that is returned from an Address.Hash() call

type IPReadHeader

type IPReadHeader struct {
	Rip, Lip   *Address
	B, Payload []byte
}

IPReadHeader contains the fields that are passed to transport layer protocols.

type Netmask

type Netmask uint8

Netmask is a network's netmask

type ReadWriter

type ReadWriter interface {
	ReadFrom() (*IPReadHeader, error)
	WriteTo(data []byte) (int, error)
	io.Closer
}

ReadWriter allows a bidirectional IP "connection": one that allows both reading and writing

func NewReadWriter

func NewReadWriter(ip *Address, protocol uint8) (ReadWriter, error)

NewReadWriter creates a ReadWriter given an IP Address and an IP protocol

type Reader

type Reader interface {
	ReadFrom() (*IPReadHeader, error)
	io.Closer
}

Reader allows reading from a specific IP protocol and address

func NewReader

func NewReader(ip *Address, protocol uint8) (Reader, error)

NewReader creates a new IPv4 Reader given an IP Address and an IP protocol number

type RoutingTable

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

RoutingTable stores the different routes that may be used

var GlobalRoutingTable *RoutingTable

GlobalRoutingTable is the routing table that is used by IPv4 and all transport layer protocols

func (*RoutingTable) Query

func (table *RoutingTable) Query(dst *Address) (src *Address)

Query returns the source IP address that will be sent from given the IP address that should be sent to.

type Writer

type Writer interface {
	WriteTo(data []byte) (int, error)
	io.Closer
}

Writer allows writing to a specific IP protocol and address

func NewWriter

func NewWriter(dst *Address, protocol uint8) (Writer, error)

NewWriter creates a new IPv4 Writer, given an Address and a protocol

Jump to

Keyboard shortcuts

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