Documentation ¶
Index ¶
- Variables
- func ComparePayload(payload1, payload2 []byte, start, end int) (bool, []string)
- func EncodeIPPacket(localIP, dstIP string, localPort, remotePort uint16, payload []byte, ...) ([]byte, error)
- func EncodePayload(ts, seq uint64, payload []byte, payloadType PayloadType) error
- func EncodePayloadWithPort(ts, seq uint64, srcPort, dstPort uint16, payload []byte, ...) error
- func Make5APaylod(size int) []byte
- func MakeFullOnePaylod(size int) []byte
- func MakeFullRandomPaylod(size int) []byte
- func MakeFullZeroPaylod(size int) []byte
- func MakePayload(payloadType PayloadType, size int) []byte
- func SimpleEncodeIPPacket(localIP, dstIP string, localPort, remotePort uint16, payload []byte) ([]byte, error)
- type DualConn
- func (c *DualConn) Close() error
- func (c *DualConn) Read(b []byte) (int, error)
- func (c *DualConn) ReadFrom(b []byte) (n int, addr net.Addr, err error)
- func (c *DualConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error)
- func (c *DualConn) ReadFromUDPAddrPort(b []byte) (n int, addr netip.AddrPort, err error)
- func (c *DualConn) ReadMsgUDPAddrPort(b, oob []byte) (n, oobn, flags int, addr netip.AddrPort, err error)
- func (c *DualConn) SetBBF(filter []bpf.RawInstruction) error
- func (c *DualConn) SetBBFExpr(expr string) error
- func (c *DualConn) SetIPv4Flag(flag IPv4Flag)
- func (c *DualConn) SetTOS(tos uint8)
- func (c *DualConn) SetTTL(ttl uint8)
- func (c *DualConn) SetTimeout(timeout time.Duration)
- func (c *DualConn) WriteToIP(payload []byte, localIP, remoteIP string, localPort, remotePort uint16) (int, error)
- type IPv4Flag
- type PayloadType
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
Make5APaylod makes a full 0x5A payload with the given size.
func MakeFullOnePaylod ¶
MakeFullOnePaylod makes a full one payload with the given size.
func MakeFullRandomPaylod ¶
MakeFullRandomPaylod makes a full random payload with the given size.
func MakeFullZeroPaylod ¶
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.
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 ¶
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) Read ¶
ReadFrom reads a UDP packet from the connection. It returns the number of bytes read, the source address and the error.
func (*DualConn) ReadFrom ¶
ReadFrom reads a UDP packet from the connection. It returns the number of bytes read, the source address and the error.
func (*DualConn) ReadFromUDP ¶
ReadFromUDP reads a UDP packet from the connection. It returns the number of bytes read, the source address and the error.
func (*DualConn) ReadFromUDPAddrPort ¶
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 ¶
SetBBFExpr sets the BPF filter for the connection. It parses the filter expression like tcpdump and sets the BPF filter.
func (*DualConn) SetIPv4Flag ¶
SetIPv4Flag sets the IPv4 flag for the connection.
func (*DualConn) SetTimeout ¶
SetTimeout sets the timeout for the connection.
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.