This repository has been archived by the owner on Feb 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathaddress.go
60 lines (51 loc) · 1.75 KB
/
address.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package godivert
import "fmt"
// Represents a WinDivertAddress struct
// See : https://reqrypt.org/windivert-doc.html#divert_address
// As go doesn't not support bit fields
// we use a little trick to get the Direction, Loopback, Import and PseudoChecksum fields
type WinDivertAddress struct {
Timestamp int64
IfIdx uint32
SubIfIdx uint32
Data uint8
}
func (w *WinDivertAddress) String() string {
return fmt.Sprintf("{\n"+
"\t\tTimestamp=%d\n"+
"\t\tInteface={IfIdx=%d SubIfIdx=%d}\n"+
"\t\tDirection=%v\n"+
"\t\tLoopback=%t\n"+
"\t\tImpostor=%t\n"+
"\t\tPseudoChecksum={IP=%t TCP=%t UDP=%t}\n"+
"\t}",
w.Timestamp, w.IfIdx, w.SubIfIdx, w.Direction(), w.Loopback(), w.Impostor(),
w.PseudoIPChecksum(), w.PseudoTCPChecksum(), w.PseudoUDPChecksum())
}
// Returns the direction of the packet
// WinDivertDirectionInbound (true) for inbounds packets
// WinDivertDirectionOutbounds (false) for outbounds packets
func (w *WinDivertAddress) Direction() Direction {
return Direction(w.Data&0x1 == 1)
}
// Returns true if the packet is a loopback packet
func (w *WinDivertAddress) Loopback() bool {
return (w.Data>>1)&0x1 == 1
}
// Returns true if the packet is an impostor
// See https://reqrypt.org/windivert-doc.html#divert_address for more information
func (w *WinDivertAddress) Impostor() bool {
return (w.Data>>2)&0x1 == 1
}
// Returns true if the packet uses a pseudo IP checksum
func (w *WinDivertAddress) PseudoIPChecksum() bool {
return (w.Data>>3)&0x1 == 1
}
// Returns true if the packet uses a pseudo TCP checksum
func (w *WinDivertAddress) PseudoTCPChecksum() bool {
return (w.Data>>4)&0x1 == 1
}
// Returns true if the packet uses a pseudo UDP checksum
func (w *WinDivertAddress) PseudoUDPChecksum() bool {
return (w.Data>>5)&0x1 == 1
}