func (b IPv4) SetTotalLength(totalLength uint16) {
	binary.BigEndian.PutUint16(b[totalLen:], totalLength)
}
SetTotalLength sets the "total length" field of the ipv4 header.
package header
import (
	"encoding/binary"
	tcpip "github.com/brewlin/net-protocol/protocol"
)
const (
	versIHL  = 0
	tos      = 1
	totalLen = 2
	id       = 4
	flagsFO  = 6
	ttl      = 8
	protocol = 9
	checksum = 10
	srcAddr  = 12
	dstAddr  = 16
)
type IPv4Fields struct {
	IHL uint8
	TOS uint8
	TotalLength uint16
	ID uint16
	Flags uint8
	FragmentOffset uint16
	TTL uint8
	Protocol uint8
	Checksum uint16
	SrcAddr tcpip.Address
	DstAddr tcpip.Address
}
type IPv4 []byte
const (
	IPv4MinimumSize = 20
	IPv4MaximumHeaderSize = 60
	IPv4AddressSize = 4
	IPv4ProtocolNumber tcpip.NetworkProtocolNumber = 0x0800
	IPv4Version = 4
	IPv4Broadcast tcpip.Address = "\xff\xff\xff\xff"
	IPv4Any tcpip.Address = "\x00\x00\x00\x00"
)
const (
	IPv4FlagMoreFragments = 1 << iota
	IPv4FlagDontFragment
)
func IPVersion(b []byte) int {
	if len(b) < versIHL+1 {
		return -1
	}
	return int(b[versIHL] >> 4)
}
func (b IPv4) HeaderLength() uint8 {
	return (b[versIHL] & 0xf) * 4
}
func (b IPv4) ID() uint16 {
	return binary.BigEndian.Uint16(b[id:])
}
func (b IPv4) Protocol() uint8 {
	return b[protocol]
}
func (b IPv4) Flags() uint8 {
	return uint8(binary.BigEndian.Uint16(b[flagsFO:]) >> 13)
}
func (b IPv4) TTL() uint8 {
	return b[ttl]
}
func (b IPv4) FragmentOffset() uint16 {
	return binary.BigEndian.Uint16(b[flagsFO:]) << 3
}
func (b IPv4) TotalLength() uint16 {
	return binary.BigEndian.Uint16(b[totalLen:])
}
func (b IPv4) Checksum() uint16 {
	return binary.BigEndian.Uint16(b[checksum:])
}
func (b IPv4) SourceAddress() tcpip.Address {
	return tcpip.Address(b[srcAddr : srcAddr+IPv4AddressSize])
}
func (b IPv4) DestinationAddress() tcpip.Address {
	return tcpip.Address(b[dstAddr : dstAddr+IPv4AddressSize])
}
func (b IPv4) TransportProtocol() tcpip.TransportProtocolNumber {
	return tcpip.TransportProtocolNumber(b.Protocol())
}
func (b IPv4) Payload() []byte {
	return b[b.HeaderLength():][:b.PayloadLength()]
}
func (b IPv4) PayloadLength() uint16 {
	return b.TotalLength() - uint16(b.HeaderLength())
}
func (b IPv4) TOS() (uint8, uint32) {
	return b[tos], 0
}
func (b IPv4) SetTOS(v uint8, _ uint32) {
	b[tos] = v
}