Documentation
¶
Index ¶
- Constants
- type ChecksumFlag
- type Direction
- type Event
- type Filter
- type Flag
- type Layer
- type LibraryReference
- func (l *LibraryReference) CalcChecksums(packet *Packet, flags ChecksumFlag)
- func (l *LibraryReference) Close(handle uintptr) error
- func (l *LibraryReference) CompileFilter(filter Filter, layer Layer) (object Filter, errorPosition uint, err error)
- func (l *LibraryReference) DecrementTTL(packet *Packet) (bool, error)
- func (l *LibraryReference) EvalFilter(packet *Packet, filter Filter) (bool, error)
- func (l *LibraryReference) FormatFilter(filter Filter, layer Layer) (object Filter, err error)
- func (l *LibraryReference) GetParam(handle uintptr, param Param) (value uint64, err error)
- func (l *LibraryReference) Open(filter Filter, layer Layer, priority Priority, flag Flag) (handle uintptr, err error)
- func (l *LibraryReference) Recv(handle uintptr, receiveBufferSize uint) (*Packet, error)
- func (l *LibraryReference) Send(handle uintptr, packet *Packet) (uint, error)
- func (l *LibraryReference) SetParam(handle uintptr, param Param, value uint64) (err error)
- func (l *LibraryReference) Shutdown(handle uintptr, how Shutdown) error
- type Packet
- type Param
- type Priority
- type Shutdown
- type WinDivertAddress
- func (a *WinDivertAddress) Direction() Direction
- func (a *WinDivertAddress) Event() Event
- func (a *WinDivertAddress) Flow() WinDivertDataFlow
- func (a *WinDivertAddress) IPChecksumValid() bool
- func (a *WinDivertAddress) IPv6() bool
- func (a *WinDivertAddress) Impostor() bool
- func (a *WinDivertAddress) Layer() Layer
- func (a *WinDivertAddress) Loopback() bool
- func (a *WinDivertAddress) Network() WinDivertDataNetwork
- func (a *WinDivertAddress) Reflect() WinDivertDataReflect
- func (a *WinDivertAddress) Sniffed() bool
- func (a *WinDivertAddress) Socket() WinDivertDataSocket
- func (a *WinDivertAddress) TCPChecksumValid() bool
- func (a *WinDivertAddress) UDPChecksumValid() bool
- type WinDivertDataFlow
- func (d *WinDivertDataFlow) Endpoint() uint64
- func (d *WinDivertDataFlow) LocalAddr() netip.Addr
- func (d *WinDivertDataFlow) LocalPort() uint16
- func (d *WinDivertDataFlow) ParentEndpoint() uint64
- func (d *WinDivertDataFlow) ProcessId() uint32
- func (d *WinDivertDataFlow) Protocol() uint8
- func (d *WinDivertDataFlow) RemoteAddr() netip.Addr
- func (d *WinDivertDataFlow) RemotePort() uint16
- type WinDivertDataNetwork
- type WinDivertDataReflect
- type WinDivertDataSocket
- func (d *WinDivertDataSocket) Endpoint() uint64
- func (d *WinDivertDataSocket) LocalAddr() netip.Addr
- func (d *WinDivertDataSocket) LocalPort() uint16
- func (d *WinDivertDataSocket) ParentEndpoint() uint64
- func (d *WinDivertDataSocket) ProcessId() uint32
- func (d *WinDivertDataSocket) Protocol() uint8
- func (d *WinDivertDataSocket) RemoteAddr() netip.Addr
- func (d *WinDivertDataSocket) RemotePort() uint16
Constants ¶
const WinDivertBatchMax = 0xFF /* 255 */
const WinDivertMTUMax = 40 + 0xFFFF
const WinDivertParamQueueLengthDefault = 4096
const WinDivertParamQueueLengthMax = 16384
const WinDivertParamQueueLengthMin = 32
const WinDivertParamQueueSizeDefault = 4194304 /* 4MB */
const WinDivertParamQueueSizeMax = 33554432 /* 32MB */
const WinDivertParamQueueSizeMin = 65535 /* 64KB */
const WinDivertParamQueueTimeDefault = 2000 /* 2s */
const WinDivertParamQueueTimeMax = 16000 /* 16s */
const WinDivertParamQueueTimeMin = 100 /* 100ms */
const WinDivertPriorityDefault = Priority(0)
const WinDivertPriorityHighest = Priority(30000)
const WinDivertPriorityLowest = Priority(-WinDivertPriorityHighest)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChecksumFlag ¶
type ChecksumFlag int64
const ( All ChecksumFlag = 0x00 NoIP ChecksumFlag = 0x01 NoICMP ChecksumFlag = 0x02 NoICMPv6 ChecksumFlag = 0x04 NoTCP ChecksumFlag = 0x08 NoUDP ChecksumFlag = 0x10 )
func (ChecksumFlag) String ¶
func (i ChecksumFlag) String() string
type LibraryReference ¶
type LibraryReference struct { // WinDivertOpen opens a WinDivert handle. WinDivertOpen *syscall.LazyProc `func:"WinDivertOpen"` // WinDivertRecv receives (reads) a packet from a WinDivert handle. WinDivertRecv *syscall.LazyProc `func:"WinDivertRecv"` // WinDivertRecvEx receives (reads) a packet from a WinDivert handle. WinDivertRecvEx *syscall.LazyProc `func:"WinDivertRecvEx"` // WinDivertSend sends (writes/injects) a packet to a WinDivert handle. WinDivertSend *syscall.LazyProc `func:"WinDivertSend"` // WinDivertSendEx sends (writes/injects) a packet to a WinDivert handle. WinDivertSendEx *syscall.LazyProc `func:"WinDivertSendEx"` // WinDivertShutdown shuts down a WinDivert handle. WinDivertShutdown *syscall.LazyProc `func:"WinDivertShutdown"` // WinDivertClose closes a WinDivert handle. WinDivertClose *syscall.LazyProc `func:"WinDivertClose"` // WinDivertSetParam sets a WinDivert handle parameter. WinDivertSetParam *syscall.LazyProc `func:"WinDivertSetParam"` // WinDivertGetParam gets a WinDivert handle parameter. WinDivertGetParam *syscall.LazyProc `func:"WinDivertGetParam"` WinDivertHelperParsePacket *syscall.LazyProc `func:"WinDivertHelperParsePacket"` WinDivertHelperHashPacket *syscall.LazyProc `func:"WinDivertHelperHashPacket"` WinDivertHelperParseIPv4Address *syscall.LazyProc `func:"WinDivertHelperParseIPv4Address"` WinDivertHelperParseIPv6Address *syscall.LazyProc `func:"WinDivertHelperParseIPv6Address"` WinDivertHelperFormatIPv4Address *syscall.LazyProc `func:"WinDivertHelperFormatIPv4Address"` WinDivertHelperFormatIPv6Address *syscall.LazyProc `func:"WinDivertHelperFormatIPv6Address"` WinDivertHelperCalcChecksums *syscall.LazyProc `func:"WinDivertHelperCalcChecksums"` WinDivertHelperDecrementTTL *syscall.LazyProc `func:"WinDivertHelperDecrementTTL"` WinDivertHelperCompileFilter *syscall.LazyProc `func:"WinDivertHelperCompileFilter"` WinDivertHelperEvalFilter *syscall.LazyProc `func:"WinDivertHelperEvalFilter"` WinDivertHelperFormatFilter *syscall.LazyProc `func:"WinDivertHelperFormatFilter"` WinDivertHelperNtohs *syscall.LazyProc `func:"WinDivertHelperNtohs"` WinDivertHelperNtohl *syscall.LazyProc `func:"WinDivertHelperNtohl"` WinDivertHelperNtohll *syscall.LazyProc `func:"WinDivertHelperNtohll"` WinDivertHelperNtohIPv6Address *syscall.LazyProc `func:"WinDivertHelperNtohIPv6Address"` WinDivertHelperHtons *syscall.LazyProc `func:"WinDivertHelperHtons"` WinDivertHelperHtonl *syscall.LazyProc `func:"WinDivertHelperHtonl"` WinDivertHelperHtonll *syscall.LazyProc `func:"WinDivertHelperHtonll"` WinDivertHelperHtonIPv6Address *syscall.LazyProc `func:"WinDivertHelperHtonIPv6Address"` // contains filtered or unexported fields }
LibraryReference contains functions to a memory copy of WinDivert.dll.
func NewDLLReference ¶
func NewDLLReference(dllPath string) (ret *LibraryReference, err error)
NewDLLReference loads the WinDivert DLL into the program and makes all function pointers available.
func (*LibraryReference) CalcChecksums ¶
func (l *LibraryReference) CalcChecksums(packet *Packet, flags ChecksumFlag)
(Re)calculates the checksum for any IPv4/ICMP/ICMPv6/TCP/UDP checksum present in the given packet. Individual checksum calculations may be disabled via the appropriate flag. Typically this function should be invoked on a modified packet before it is injected with WinDivertSend(). By default this function will calculate each checksum from scratch, even if the existing checksum is correct. This may be inefficient for some applications. For better performance, incremental checksum calculations should be used instead (not provided by this API). If pAddr is non-NULL, this function sets the corresponding *Checksum flag (see WINDIVERT_ADDRESS). Normally, pAddr should point to the address passed to WinDivertSend() for packet injection. https://reqrypt.org/windivert-doc.html#divert_helper_calc_checksums
func (*LibraryReference) Close ¶
func (l *LibraryReference) Close(handle uintptr) error
Close closes the handle See https://reqrypt.org/windivert-doc.html#divert_close
func (*LibraryReference) CompileFilter ¶
func (l *LibraryReference) CompileFilter(filter Filter, layer Layer) (object Filter, errorPosition uint, err error)
https://reqrypt.org/windivert-doc.html#divert_helper_compile_filter
func (*LibraryReference) DecrementTTL ¶
func (l *LibraryReference) DecrementTTL(packet *Packet) (bool, error)
Decrements the ip.TTL or ipv6.HopHimit field by 1, and returns TRUE only if the result is non-zero. This is useful for applications where packet loops may be a problem. For IPv4, this function will preserve the validity of the IPv4 checksum. That is, if the packet had a valid checksum before the operation, the resulting checksum will also be valid after the operation. This function updates the checksum field incrementally. https://reqrypt.org/windivert-doc.html#divert_helper_dec_ttl
func (*LibraryReference) EvalFilter ¶
func (l *LibraryReference) EvalFilter(packet *Packet, filter Filter) (bool, error)
Evaluates the given packet against the given packet filter string. This function returns TRUE if the packet matches, and returns FALSE otherwise. This function also returns FALSE if an error occurs, in which case GetLastError() can be used to get the reason for the error. Otherwise, if no error occurred, GetLastError() will return 0. Note that this function is relatively slow since the packet filter string will be (re)compiled for each call. This overhead can be minimized by pre-compiling the filter string into the object representation using the WinDivertHelperCompileFilter() function. https://reqrypt.org/windivert-doc.html#divert_helper_eval_filter
func (*LibraryReference) FormatFilter ¶
func (l *LibraryReference) FormatFilter(filter Filter, layer Layer) (object Filter, err error)
https://reqrypt.org/windivert-doc.html#divert_helper_format_filter
func (*LibraryReference) GetParam ¶
func (l *LibraryReference) GetParam(handle uintptr, param Param) (value uint64, err error)
func (*LibraryReference) Open ¶
func (l *LibraryReference) Open(filter Filter, layer Layer, priority Priority, flag Flag) (handle uintptr, err error)
Open opens a new WinDivert handle.
func (*LibraryReference) Recv ¶
func (l *LibraryReference) Recv(handle uintptr, receiveBufferSize uint) (*Packet, error)
Recv diverts a packet from the network stack https://reqrypt.org/windivert-doc.html#divert_recv
func (*LibraryReference) Send ¶
func (l *LibraryReference) Send(handle uintptr, packet *Packet) (uint, error)
Send injects the packet on the network stack https://reqrypt.org/windivert-doc.html#divert_send
type Packet ¶
type Packet struct { Address *WinDivertAddress Length uint Content []byte }
Wrapped packet
type Priority ¶
type Priority int16
Priority of the handles Multiple handles should not have the same priority.
type WinDivertAddress ¶
type WinDivertAddress struct { // A timestamp indicating when event occurred. Timestamp int64 // contains filtered or unexported fields }
WINDIVERT_ADDRESS https://reqrypt.org/windivert-doc.html#divert_address
func (*WinDivertAddress) Direction ¶
func (a *WinDivertAddress) Direction() Direction
Direction returns the direction of the packet
func (*WinDivertAddress) Event ¶
func (a *WinDivertAddress) Event() Event
The captured event (WINDIVERT_EVENT_*).
func (*WinDivertAddress) Flow ¶
func (a *WinDivertAddress) Flow() WinDivertDataFlow
func (*WinDivertAddress) IPChecksumValid ¶
func (a *WinDivertAddress) IPChecksumValid() bool
Set to 1 if the IPv4 checksum is valid, 0 otherwise.
func (*WinDivertAddress) IPv6 ¶
func (a *WinDivertAddress) IPv6() bool
Set to 1 for IPv6 packets/events, 0 otherwise.
func (*WinDivertAddress) Impostor ¶
func (a *WinDivertAddress) Impostor() bool
Set to 1 for impostor packets, 0 otherwise.
func (*WinDivertAddress) Layer ¶
func (a *WinDivertAddress) Layer() Layer
The handle's layer (WINDIVERT_LAYER_*).
func (*WinDivertAddress) Loopback ¶
func (a *WinDivertAddress) Loopback() bool
Set to 1 for loopback packets, 0 otherwise.
func (*WinDivertAddress) Network ¶
func (a *WinDivertAddress) Network() WinDivertDataNetwork
func (*WinDivertAddress) Reflect ¶
func (a *WinDivertAddress) Reflect() WinDivertDataReflect
func (*WinDivertAddress) Sniffed ¶
func (a *WinDivertAddress) Sniffed() bool
Set to 1 if the event was sniffed (i.e., not blocked), 0 otherwise.
func (*WinDivertAddress) Socket ¶
func (a *WinDivertAddress) Socket() WinDivertDataSocket
func (*WinDivertAddress) TCPChecksumValid ¶
func (a *WinDivertAddress) TCPChecksumValid() bool
Set to 1 if the TCP checksum is valid, 0 otherwise.
func (*WinDivertAddress) UDPChecksumValid ¶
func (a *WinDivertAddress) UDPChecksumValid() bool
Set to 1 if the UDP checksum is valid, 0 otherwise.
type WinDivertDataFlow ¶
type WinDivertDataFlow addressInternalUnion
WINDIVERT_DATA_FLOW
func (*WinDivertDataFlow) Endpoint ¶
func (d *WinDivertDataFlow) Endpoint() uint64
The endpoint ID of the flow.
func (*WinDivertDataFlow) LocalAddr ¶
func (d *WinDivertDataFlow) LocalAddr() netip.Addr
func (*WinDivertDataFlow) LocalPort ¶
func (d *WinDivertDataFlow) LocalPort() uint16
func (*WinDivertDataFlow) ParentEndpoint ¶
func (d *WinDivertDataFlow) ParentEndpoint() uint64
The parent endpoint ID of the flow.
func (*WinDivertDataFlow) ProcessId ¶
func (d *WinDivertDataFlow) ProcessId() uint32
The ID of the process associated with the flow.
func (*WinDivertDataFlow) Protocol ¶
func (d *WinDivertDataFlow) Protocol() uint8
func (*WinDivertDataFlow) RemoteAddr ¶
func (d *WinDivertDataFlow) RemoteAddr() netip.Addr
func (*WinDivertDataFlow) RemotePort ¶
func (d *WinDivertDataFlow) RemotePort() uint16
type WinDivertDataNetwork ¶
type WinDivertDataNetwork addressInternalUnion
WINDIVERT_DATA_NETWORK
func (*WinDivertDataNetwork) IfIdx ¶
func (d *WinDivertDataNetwork) IfIdx() uint32
The interface index on which the packet arrived (for inbound packets), or is to be sent (for outbound packets).
func (*WinDivertDataNetwork) SubIfIdx ¶
func (d *WinDivertDataNetwork) SubIfIdx() uint32
The sub-interface index for IfIdx.
type WinDivertDataReflect ¶
type WinDivertDataReflect addressInternalUnion
WINDIVERT_DATA_REFLECT
func (*WinDivertDataReflect) Flags ¶
func (d *WinDivertDataReflect) Flags() Flag
func (*WinDivertDataReflect) Layer ¶
func (d *WinDivertDataReflect) Layer() Layer
func (*WinDivertDataReflect) Priority ¶
func (d *WinDivertDataReflect) Priority() int16
func (*WinDivertDataReflect) ProcessId ¶
func (d *WinDivertDataReflect) ProcessId() uint32
The ID of the process that opened the handle.
func (*WinDivertDataReflect) Timestamp ¶
func (d *WinDivertDataReflect) Timestamp() int64
A timestamp indicating when the handle was opened.
type WinDivertDataSocket ¶
type WinDivertDataSocket addressInternalUnion
WINDIVERT_DATA_SOCKET
func (*WinDivertDataSocket) Endpoint ¶
func (d *WinDivertDataSocket) Endpoint() uint64
The endpoint ID of the socket operation.
func (*WinDivertDataSocket) LocalAddr ¶
func (d *WinDivertDataSocket) LocalAddr() netip.Addr
func (*WinDivertDataSocket) LocalPort ¶
func (d *WinDivertDataSocket) LocalPort() uint16
func (*WinDivertDataSocket) ParentEndpoint ¶
func (d *WinDivertDataSocket) ParentEndpoint() uint64
The parent endpoint ID of the socket operation.
func (*WinDivertDataSocket) ProcessId ¶
func (d *WinDivertDataSocket) ProcessId() uint32
The ID of the process associated with the socket operation.
func (*WinDivertDataSocket) Protocol ¶
func (d *WinDivertDataSocket) Protocol() uint8
func (*WinDivertDataSocket) RemoteAddr ¶
func (d *WinDivertDataSocket) RemoteAddr() netip.Addr
func (*WinDivertDataSocket) RemotePort ¶
func (d *WinDivertDataSocket) RemotePort() uint16