RawSocket

package
v0.0.0-...-4420913 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func GetSelfIP

func GetSelfIP() net.IP

GetSelfIP returns the IP address of the current machine.

Types

type ICMP

type ICMP struct {
	Type                    layers.ICMPv4TypeCode
	Payload                 []byte
	RandomizedPayloadLength int
}

func (*ICMP) Build

func (icmp *ICMP) Build(src, dest net.IPAddr) []byte

Build constructs an ICMP packet with the given source and destination IP addresses. The function returns the byte representation of the constructed packet.

type IPIterator

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

IPIterator represents an iterator over a collection of IP addresses.

func ToIPIterator

func ToIPIterator(data ...string) *IPIterator

ToIPIterator creates a new instance of IPIterator with the given data.

func (*IPIterator) HasNext

func (it *IPIterator) HasNext() bool

HasNext returns true if there is a next IP address in the iterator.

func (*IPIterator) Next

func (it *IPIterator) Next() net.IP

Next returns the next IP in the iterator.

func (*IPIterator) SetSkipLocal

func (it *IPIterator) SetSkipLocal(b bool)

SetSkipLocal sets the skipLocal flag to the given value.

func (*IPIterator) Shuffle

func (it *IPIterator) Shuffle()

type ProtocolType

type ProtocolType int

func (ProtocolType) LinkType

func (t ProtocolType) LinkType() gopacket.Decoder

LinkType returns the corresponding gopacket.Decoder for the given ProtocolType.

type RawSocket

type RawSocket interface {
	Write([]byte, net.Addr) (int, error)
	Read([]byte) (int, net.Addr, error)
	NextPacket() (gopacket.Packet, *net.IPAddr, error)
	Iter() chan WrappedPacket
	Close() error
}

func OpenRawSocket

func OpenRawSocket(protocol ProtocolType) (RawSocket, error)

OpenRawSocket opens a raw socket for the specified protocol. It returns a pointer to RawSocket and an error, if any.

type TCP

type TCP struct {
	SYN, ACK, RST, PSH, FIN, URG, ECE, CWR, NS bool
	Payload                                    []byte
	RandomizedPayloadLength                    int
	Options                                    []layers.TCPOption
	Sequence                                   uint32
	Randomize                                  bool
	Window                                     uint16
	AckNum                                     uint32
}

func (*TCP) Build

func (tcp *TCP) Build(src, dest net.TCPAddr) []byte

Build creates a TCP packet with the given source and destination addresses. It returns the serialized packet as a byte slice.

type UDP

type UDP struct {
	Payload                 []byte
	RandomizedPayloadLength int
}

func (*UDP) Build

func (udp *UDP) Build(src, dest net.UDPAddr) []byte

Build generates a UDP packet with the provided source and destination addresses. It returns the serialized packet as a byte slice.

type UnixSocket

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

func (*UnixSocket) Close

func (u *UnixSocket) Close() error

Close closes the UnixSocket connection. It returns an error if there was an issue closing the connection.

func (*UnixSocket) Iter

func (u *UnixSocket) Iter() chan WrappedPacket

Iter returns a channel that will receive gopacket.Packet objects.

func (*UnixSocket) NextPacket

func (u *UnixSocket) NextPacket() (gopacket.Packet, *net.IPAddr, error)

NextPacket reads the next packet from the UnixSocket. It returns the packet as a gopacket.Packet and any error encountered.

func (*UnixSocket) Read

func (u *UnixSocket) Read(bytes []byte) (int, net.Addr, error)

Read reads data from the Unix socket connection. It reads up to len(bytes) bytes into the provided byte slice. It returns the number of bytes read, the network address of the remote socket, and any error encountered.

func (*UnixSocket) Write

func (u *UnixSocket) Write(bytes []byte, addr net.Addr) (int, error)

Write writes the given bytes to the specified address using the UnixSocket connection. It returns the number of bytes written and any error that occurred.

type WrappedPacket

type WrappedPacket struct {
	*net.IPAddr
	gopacket.Packet
}

Jump to

Keyboard shortcuts

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