-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotifier_impl_windows.go
75 lines (63 loc) · 1.47 KB
/
notifier_impl_windows.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
//+build windows
package networkchangenotifier
import (
"syscall"
"unsafe"
"golang.org/x/sys/windows"
)
var iphlpapi = windows.NewLazySystemDLL("iphlpapi.dll")
var notifyRouteChange2 = iphlpapi.NewProc("NotifyRouteChange2")
var cancelMibChangeNotify2 = iphlpapi.NewProc("CancelMibChangeNotify2")
var h windows.Handle
func ncnInit() error {
var err error
ret, err := NotifyRouteChange2(
uint16(windows.AF_UNSPEC),
callback_windows,
0,
0,
&h,
)
if ret == windows.NO_ERROR {
err = nil
}
return err
}
func ncnRegisterCallback() {
}
func ncnUnregisterCallback() {
}
func ncnCleanup() error {
var err error
ret, err := CancelMibChangeNotify2(
h,
)
if ret == windows.NO_ERROR {
err = nil
}
return err
}
type PIPFORWARD_CHANGE_CALLBACK func(CallerContext windows.Handle, Row windows.Handle, NotificationType int) uintptr
func NotifyRouteChange2(
AddressFamily uint16,
Callback PIPFORWARD_CHANGE_CALLBACK,
CallerContext windows.Handle,
InitialNotification uint8,
NotificationHandle *windows.Handle,
) (uint32, error) {
cb := syscall.NewCallback(Callback)
ret, _, err := notifyRouteChange2.Call(
uintptr(AddressFamily),
cb,
uintptr(unsafe.Pointer(&CallerContext)),
uintptr(InitialNotification),
uintptr(unsafe.Pointer(NotificationHandle)),
)
return uint32(ret), err
}
func CancelMibChangeNotify2(NotificationHandle windows.Handle) (uint32, error) {
ret, _, err := cancelMibChangeNotify2.Call(
uintptr(NotificationHandle),
)
return uint32(ret), err
}