dualconn

package module
v0.0.0-...-9f32f27 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 12 Imported by: 0

README

dualconn

一半是水,一半是火。

你猜它是干啥的?

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPayloadTooShort is returned when the payload is too short.
	ErrPayloadTooShort = errors.New("payload too short")
	// ErrPayloadNotMatch is returned when the timestamp or sequence or payloadType number mismatch.
	ErrPayloadNotMatch = errors.New("timestamp or sequence or payloadType number mismatch")
)

Functions

func ComparePayload

func ComparePayload(payload1, payload2 []byte, start, end int) (bool, []string)

ComparePayload compares two payloads and returns whether they are different and the changes.

func EncodeIPPacket

func EncodeIPPacket(localIP, dstIP string, localPort, remotePort uint16, payload []byte,
	ttl, tos uint8, ipv4Flags layers.IPv4Flag) ([]byte, error)

EncodeIPPacket encodes a UDP packet with the given parameters.

func EncodePayload

func EncodePayload(ts, seq uint64, payload []byte, payloadType PayloadType) error

EncodePayload encodes the timestamp and sequence number into head of the payload.

func EncodePayloadWithPort

func EncodePayloadWithPort(ts, seq uint64, srcPort, dstPort uint16, payload []byte, payloadType PayloadType) error

EncodePayloadWithPort encodes the timestamp, sequence number, src port and dst port into head of the payload.

func Make5APaylod

func Make5APaylod(size int) []byte

Make5APaylod makes a full 0x5A payload with the given size.

func MakeFullOnePaylod

func MakeFullOnePaylod(size int) []byte

MakeFullOnePaylod makes a full one payload with the given size.

func MakeFullRandomPaylod

func MakeFullRandomPaylod(size int) []byte

MakeFullRandomPaylod makes a full random payload with the given size.

func MakeFullZeroPaylod

func MakeFullZeroPaylod(size int) []byte

MakeFullZeroPaylod makes a full zero payload with the given size.

func MakePayload

func MakePayload(payloadType PayloadType, size int) []byte

MakePayload makes a payload with the given type and size.

func SimpleEncodeIPPacket

func SimpleEncodeIPPacket(localIP, dstIP string, localPort, remotePort uint16, payload []byte) ([]byte, error)

SimpleEncodeIPPacket encodes a UDP packet simply with the given parameters.

Types

type DualConn

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

DualConn represents a connection that combines an IPv4 raw connection and a UDP connection. It is used to send UDP packets with raw IP headers. And receive UDP packets with net.recvConn.

func NewDualConn

func NewDualConn(localAddr string, port int) (*DualConn, error)

NewDualConn creates a new DualConn. It creates an IPv4 raw connection for sending UDP packets with raw IP headers. And a UDP connection for receiving UDP packets.

@param localAddr: the local IP address to bind for sending UDP packets @param port: the local port to bind for receiving UDP packets

func (*DualConn) Close

func (c *DualConn) Close() error

Close closes the connection.

func (*DualConn) Read

func (c *DualConn) Read(b []byte) (int, error)

ReadFrom reads a UDP packet from the connection. It returns the number of bytes read, the source address and the error.

func (*DualConn) ReadFrom

func (c *DualConn) ReadFrom(b []byte) (n int, addr net.Addr, err error)

ReadFrom reads a UDP packet from the connection. It returns the number of bytes read, the source address and the error.

func (*DualConn) ReadFromUDP

func (c *DualConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error)

ReadFromUDP reads a UDP packet from the connection. It returns the number of bytes read, the source address and the error.

func (*DualConn) ReadFromUDPAddrPort

func (c *DualConn) ReadFromUDPAddrPort(b []byte) (n int, addr netip.AddrPort, err error)

ReadFromUDP reads a UDP packet from the connection. It returns the number of bytes read, the source address and the error.

func (*DualConn) ReadMsgUDPAddrPort

func (c *DualConn) ReadMsgUDPAddrPort(b, oob []byte) (n, oobn, flags int, addr netip.AddrPort, err error)

ReadFromUDP reads a UDP packet from the connection. It returns the number of bytes read, the oob data, the flags, the source address and the error.

func (*DualConn) SetBBF

func (c *DualConn) SetBBF(filter []bpf.RawInstruction) error

SetBBF sets the BPF filter for the connection.

func (*DualConn) SetBBFExpr

func (c *DualConn) SetBBFExpr(expr string) error

SetBBFExpr sets the BPF filter for the connection. It parses the filter expression like tcpdump and sets the BPF filter.

func (*DualConn) SetIPv4Flag

func (c *DualConn) SetIPv4Flag(flag IPv4Flag)

SetIPv4Flag sets the IPv4 flag for the connection.

func (*DualConn) SetTOS

func (c *DualConn) SetTOS(tos uint8)

SetTOS sets the Type of Service (TOS) for the connection.

func (*DualConn) SetTTL

func (c *DualConn) SetTTL(ttl uint8)

SetTTL sets the Time To Live (TTL) for the connection.

func (*DualConn) SetTimeout

func (c *DualConn) SetTimeout(timeout time.Duration)

SetTimeout sets the timeout for the connection.

func (*DualConn) WriteToIP

func (c *DualConn) WriteToIP(payload []byte, localIP, remoteIP string, localPort, remotePort uint16) (int, error)

WriteToIP writes UDP data to the specified destination IP and port.

type IPv4Flag

type IPv4Flag uint8

IPv4Flag represents the flags in an IPv4 header.

type PayloadType

type PayloadType byte

PayloadType represents the type of payload.

const (
	PayloadTypeZero PayloadType = iota
	PayloadTypeOne
	PayloadType5A
	PayloadTypeRandom
)

func DecodePayload

func DecodePayload(payload []byte) (ts, seq uint64, payloadType PayloadType, err error)

DecodePayload decodes the timestamp and sequence number from the head of the payload.

func DecodePayloadWithPort

func DecodePayloadWithPort(payload []byte) (ts, seq uint64, srcPort, dstPort uint16, payloadType PayloadType, err error)

DecodePayloadWithPort decodes the timestamp, sequence number, src port and dst port from the head of the payload.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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