-
Notifications
You must be signed in to change notification settings - Fork 7
/
address.go
208 lines (165 loc) · 3.73 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package windivert
import (
"unsafe"
)
type Ethernet struct {
InterfaceIndex uint32
SubInterfaceIndex uint32
_ [7]uint64
}
type Network struct {
InterfaceIndex uint32
SubInterfaceIndex uint32
_ [7]uint64
}
type Socket struct {
EndpointID uint64
ParentEndpointID uint64
ProcessID uint32
LocalAddress [16]uint8
RemoteAddress [16]uint8
LocalPort uint16
RemotePort uint16
Protocol uint8
_ [3]uint8
_ uint32
}
type Flow struct {
EndpointID uint64
ParentEndpointID uint64
ProcessID uint32
LocalAddress [16]uint8
RemoteAddress [16]uint8
LocalPort uint16
RemotePort uint16
Protocol uint8
_ [3]uint8
_ uint32
}
type Reflect struct {
TimeStamp int64
ProcessID uint32
layer uint32
Flags uint64
Priority int16
_ int16
_ int32
_ [4]uint64
}
func (r *Reflect) Layer() Layer {
return Layer(r.layer)
}
type Address struct {
Timestamp int64
layer uint8
event uint8
Flags uint8
_ uint8
length uint32
union [64]uint8
}
func (a *Address) Layer() Layer {
return Layer(a.layer)
}
func (a *Address) SetLayer(layer Layer) {
a.layer = uint8(layer)
}
func (a *Address) Event() Event {
return Event(a.event)
}
func (a *Address) SetEvent(event Event) {
a.event = uint8(event)
}
func (a *Address) Sniffed() bool {
return (a.Flags & uint8(0x01<<0)) == uint8(0x01<<0)
}
func (a *Address) SetSniffed() {
a.Flags |= uint8(0x01 << 0)
}
func (a *Address) UnsetSniffed() {
a.Flags &= ^uint8(0x01 << 0)
}
func (a *Address) Outbound() bool {
return (a.Flags & uint8(0x01<<1)) == uint8(0x01<<1)
}
func (a *Address) SetOutbound() {
a.Flags |= uint8(0x01 << 1)
}
func (a *Address) UnsetOutbound() {
a.Flags &= ^uint8(0x01 << 1)
}
func (a *Address) Loopback() bool {
return (a.Flags & uint8(0x01<<2)) == uint8(0x01<<2)
}
func (a *Address) SetLoopback() {
a.Flags |= uint8(0x01 << 2)
}
func (a *Address) UnsetLoopback() {
a.Flags &= ^uint8(0x01 << 2)
}
func (a *Address) Impostor() bool {
return (a.Flags & uint8(0x01<<3)) == uint8(0x01<<3)
}
func (a *Address) SetImpostor() {
a.Flags |= uint8(0x01 << 3)
}
func (a *Address) UnsetImpostor() {
a.Flags &= ^uint8(0x01 << 3)
}
func (a *Address) IPv6() bool {
return (a.Flags & uint8(0x01<<4)) == uint8(0x01<<4)
}
func (a *Address) SetIPv6() {
a.Flags |= uint8(0x01 << 4)
}
func (a *Address) UnsetIPv6() {
a.Flags &= ^uint8(0x01 << 4)
}
func (a *Address) IPChecksum() bool {
return (a.Flags & uint8(0x01<<5)) == uint8(0x01<<5)
}
func (a *Address) SetIPChecksum() {
a.Flags |= uint8(0x01 << 5)
}
func (a *Address) UnsetIPChecksum() {
a.Flags &= ^uint8(0x01 << 5)
}
func (a *Address) TCPChecksum() bool {
return (a.Flags & uint8(0x01<<6)) == uint8(0x01<<6)
}
func (a *Address) SetTCPChecksum() {
a.Flags |= uint8(0x01 << 6)
}
func (a *Address) UnsetTCPChecksum() {
a.Flags &= ^uint8(0x01 << 6)
}
func (a *Address) UDPChecksum() bool {
return (a.Flags & uint8(0x01<<7)) == uint8(0x01<<7)
}
func (a *Address) SetUDPChecksum() {
a.Flags |= uint8(0x01 << 7)
}
func (a *Address) UnsetUDPChecksum() {
a.Flags &= ^uint8(0x01 << 7)
}
func (a *Address) Length() uint32 {
return a.length >> 12
}
func (a *Address) SetLength(n uint32) {
a.length = n << 12
}
func (a *Address) Ethernet() *Ethernet {
return (*Ethernet)(unsafe.Pointer(&a.union))
}
func (a *Address) Network() *Network {
return (*Network)(unsafe.Pointer(&a.union))
}
func (a *Address) Socket() *Socket {
return (*Socket)(unsafe.Pointer(&a.union))
}
func (a *Address) Flow() *Flow {
return (*Flow)(unsafe.Pointer(&a.union))
}
func (a *Address) Reflect() *Reflect {
return (*Reflect)(unsafe.Pointer(&a.union))
}