divert

package module
v0.0.0-...-366fa9c Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: GPL-3.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Go bindings of WinDivert

Feature

  • Support WinDivert 2.x
  • Optional CGO support to remove dependence of WinDivert.dll, use -tags="divert_cgo"
  • Support loading dll from rsrc data, use -tags="divert_embedded"

More details about WinDivert please refer https://www.reqrypt.org/windivert-doc.html.

Usage

package main

import (
	"fmt"

	"github.com/gone-lib/divert-go"
	"golang.org/x/net/ipv4"
)

func checkPacket(handle *divert.Handle, packetChan <-chan *divert.Packet) {
	for packet := range packetChan {
		fmt.Println("Sniffed", packet.Addr.Sniffed())
		fmt.Println("Outbound", packet.Addr.Outbound())
		fmt.Println("Loopback", packet.Addr.Loopback())
		fmt.Println("Impostor", packet.Addr.Impostor())
		fmt.Println("IPv6", packet.Addr.IPv6())
		fmt.Println("IPChecksum", packet.Addr.IPChecksum())
		fmt.Println("TCPChecksum", packet.Addr.TCPChecksum())
		fmt.Println("UDPChecksum", packet.Addr.UDPChecksum())
		header, _ := ipv4.ParseHeader(packet.Content)
		fmt.Println(header)
		// divert.HelperCalcChecksum(packet, 0)
		handle.Send(packet.Content, packet.Addr)
	}
}

func main() {
	// var filter = "(outbound  and tcp.DstPort == 1800) or (inbound  and  tcp.SrcPort == 1800)"
	var filter = "true"
	handle, err := divert.Open(filter, divert.LayerNetwork, divert.PriorityLowest, 0)

	if err != nil {
		fmt.Println(err.Error())
		return
	}
	handle.SetParam(divert.QueueLength, divert.QueueLengthMax)
	handle.SetParam(divert.QueueTime, divert.QueueTimeMax)

	packetChan, err := handle.Packets()
	if err != nil {
		panic(err)
	}
	//defer handle.Close()
	checkPacket(handle, packetChan)
}

Documentation

Index

Constants

This section is empty.

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
)

type Direction

type Direction int
const (
	Outbound Direction = 1
	Inbound  Direction = 0
)

type Flag

type Flag uint8
const (
	None        Flag = 0x00
	Sniff       Flag = 0x01
	Drop        Flag = 0x02
	ReceiveOnly Flag = 0x04
	SendOnly    Flag = 0x08
	NoInstall   Flag = 0x10
	Fragments   Flag = 0x20
)

func (Flag) String

func (flags Flag) String() string

type Packet

type Packet struct {
	Content []byte
	Addr    *Address
}

func (*Packet) Decode

func (p *Packet) Decode(options gopacket.DecodeOptions) gopacket.Packet

func (*Packet) IPVersion

func (p *Packet) IPVersion() uint8

type Priority

type Priority int16

Priority of the handles Multiple handles should not have the same priority.

Directories

Path Synopsis
example
print command
version-info command
2022-02-04 https://github.com/WireGuard/wireguard-windows/tree/master/driver/memmod
2022-02-04 https://github.com/WireGuard/wireguard-windows/tree/master/driver/memmod

Jump to

Keyboard shortcuts

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