netutils

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtoInet  = "INET"
	ProtoInet6 = "INET6"
	ProtoIPv6  = "IPv6"
	ProtoIPv4  = "IPv4"

	ProtoUDP = "UDP"
	ProtoTCP = "TCP"

	SocketTCP  = "tcp"
	SocketUDP  = "udp"
	SocketUnix = "unix"
	SocketTLS  = "tcp+tls"
)
View Source
const (
	IPv6MinimumFragmentSize    = 1280
	IPv6MaximumSize            = 65535
	IPv6MaximumFragmentOffset  = 8189
	IPv6MaximumFragmentListLen = 52

	IPv4MinimumFragmentSize    = 8     // Minimum size of a single fragment
	IPv4MaximumSize            = 65535 // Maximum size of a fragment (2^16)
	IPv4MaximumFragmentOffset  = 8183  // Maximum offset of a fragment
	IPv4MaximumFragmentListLen = 8192  // Back out if we get more than this many fragments
)
View Source
const (
	IPv4ProtocolTCP      = layers.IPProtocolTCP
	IPv4ProtocolUDP      = layers.IPProtocolUDP
	IPv6ProtocolTCP      = layers.IPProtocolTCP
	IPv6ProtocolUDP      = layers.IPProtocolUDP
	IPv6ProtocolFragment = layers.IPProtocolIPv6Fragment
)

Variables

Functions

func AcceptConnections

func AcceptConnections(listener net.Listener, acceptChan chan<- net.Conn)

func ApplyBpfFilter

func ApplyBpfFilter(filter []bpf.Instruction, fd int) (err error)

func Close

func Close(conn io.Closer, reset bool) error

thanks to https://stackoverflow.com/questions/28967701/golang-tcp-socket-cant-close-after-get-file, call conn.CloseRead() before calling conn.Close()

func ConvertIP4

func ConvertIP4(ip uint32) net.IP

func ConvertIP6

func ConvertIP6(ip [4]uint32) net.IP

func GetBpfFilter

func GetBpfFilter(port int) []bpf.Instruction

func GetIPAddress

func GetIPAddress[T uint32 | [4]uint32](ip T, mapper func(T) net.IP) net.IP

func GetPeerName

func GetPeerName(peerAddr string) string

GetPeerName returns the hostname associated with the given peer address. If the peer address cannot be split into IP and port or if the hostname lookup fails, it returns the peer address or IP itself.

func Htons

func Htons(v uint16) int

Convert a uint16 to host byte order (big endian)

func IPDefragger

func IPDefragger(ipInput chan gopacket.Packet, udpOutput chan gopacket.Packet, tcpOutput chan gopacket.Packet, port int)

func IsClosedConnectionError

func IsClosedConnectionError(err error) bool

func RemoveBpfFilter

func RemoveBpfFilter(fd int) (err error)

func SetSockRCVBUF

func SetSockRCVBUF(conn net.Conn, desired int, isTLS bool) (int, int, error)

Configure SO_RCVBUF, thanks to https://github.com/dmachard/go-dns-collector/issues/61#issuecomment-1201199895

func StartToListen

func StartToListen(listenIP string, listenPort int, sockPath string, tlsSupport bool, tlsMin uint16, certFile, keyFile string) (net.Listener, error)

func TCPAssembler

func TCPAssembler(tcpInput chan gopacket.Packet, dnsOutput chan DNSPacket, portFilter int)

func UDPProcessor

func UDPProcessor(udpInput chan gopacket.Packet, dnsOutput chan DNSPacket, portFilter int)

Types

type DNSPacket

type DNSPacket struct {
	// DNS payload
	Payload []byte
	// IP layer
	IPLayer gopacket.Flow
	// Transport layer
	TransportLayer gopacket.Flow
	// Timestamp
	Timestamp time.Time
	// IP Defragmented
	IPDefragmented bool
	// TCP reassembly
	TCPReassembled bool
}

DefragPacket is a struct that holds DNS data

type DNSStreamFactory

type DNSStreamFactory struct {
	// Channel to send reassembled DNS data
	Reassembled    chan DNSPacket
	IPDefragmented bool
}

func (*DNSStreamFactory) New

func (s *DNSStreamFactory) New(net, transport gopacket.Flow) tcpassembly.Stream

type IPDefragmenter

type IPDefragmenter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewIPDefragmenter

func NewIPDefragmenter() *IPDefragmenter

func (*IPDefragmenter) DefragIP

func (d *IPDefragmenter) DefragIP(in gopacket.Packet) (gopacket.Packet, error)

func (*IPDefragmenter) DiscardOlderThan

func (d *IPDefragmenter) DiscardOlderThan(t time.Time) int

type NetDecoder

type NetDecoder struct{}

func (*NetDecoder) Decode

func (d *NetDecoder) Decode(data []byte, p gopacket.PacketBuilder) error

Jump to

Keyboard shortcuts

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