windivert

package
v1.14.0-alpha.21 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package windivert provides a pure-Go binding to the WinDivert kernel driver on Windows (amd64 and 386). User-mode WinDivert calls are reimplemented in Go; only the signed kernel driver is embedded as an asset, since SCM-installed drivers must live on disk and their Authenticode signature forbids modification.

Administrator is required for the first Open in a process so SCM can load the driver. Upstream: https://github.com/basil00/WinDivert v2.2.2, redistributed under its LGPL v3 option; see assets/LICENSE.txt.

Index

Constants

View Source
const (
	PriorityHighest int16 = 30000
	PriorityLowest  int16 = -30000
)
View Source
const AssetVersion = "2.2.2"
View Source
const MTUMax = 40 + 0xFFFF

MTUMax is WINDIVERT_MTU_MAX from windivert.h (40 + 0xFFFF). Suitable as a single-packet receive buffer size.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Timestamp int64

	Reserved2 uint32
	// contains filtered or unexported fields
}

Address mirrors WINDIVERT_ADDRESS from windivert.h (80 bytes, little-endian on both amd64 and 386):

 0: INT64  Timestamp
 8: UINT32 bitfield: Layer:8 | Event:8 | flags | Reserved1:8
12: UINT32 Reserved2
16: 64 bytes union (WINDIVERT_DATA_NETWORK / FLOW / SOCKET / REFLECT)

func (*Address) IPv6

func (a *Address) IPv6() bool

func (*Address) SetIPChecksum

func (a *Address) SetIPChecksum(v bool)

func (*Address) SetTCPChecksum

func (a *Address) SetTCPChecksum(v bool)

type Filter

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

Filter is a typed specification of packets to capture. It replaces WinDivert's filter string language.

Zero value = "reject all" (match nothing), suitable for send-only handles.

func OutboundTCP

func OutboundTCP(src, dst netip.AddrPort) (*Filter, error)

OutboundTCP returns a filter matching outbound TCP packets on the given 5-tuple. Both addresses must share an address family (IPv4 or IPv6).

type Flag

type Flag uint64
const (
	// FlagSniff opens a passive observer: the driver copies matching packets
	// to userspace without removing them from the network stack. Send is not
	// required (and not allowed) on a sniffing handle.
	FlagSniff Flag = 0x0001
	// FlagSendOnly opens a write-only injection handle; Recv is not allowed.
	FlagSendOnly Flag = 0x0008
)

type Layer

type Layer uint32
const LayerNetwork Layer = 0

Jump to

Keyboard shortcuts

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