-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathiphlpapi.go
60 lines (50 loc) · 1.9 KB
/
iphlpapi.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
// +build windows
package winnetstat
import (
"syscall"
"unsafe"
"golang.org/x/sys/windows"
)
var (
// Library
modiphlpapi = windows.NewLazySystemDLL("iphlpapi.dll")
// Functions
procGetTCPTable2 = modiphlpapi.NewProc("GetTcpTable2")
procGetTCP6Table2 = modiphlpapi.NewProc("GetTcp6Table2")
procGetExtendedTCPTable = modiphlpapi.NewProc("GetExtendedTcpTable")
procGetExtendedUDPTable = modiphlpapi.NewProc("GetExtendedUdpTable")
)
func getUintptrFromBool(b bool) uintptr {
if b {
return 1
}
return 0
}
func GetTcpTable2(tcpTable PMIB_TCPTABLE2, bufSize *uint32, order bool) (errcode error) {
r1, _, _ := syscall.Syscall(procGetTCPTable2.Addr(), 3, uintptr(unsafe.Pointer(tcpTable)), uintptr(unsafe.Pointer(bufSize)), getUintptrFromBool(order))
if r1 != 0 {
errcode = syscall.Errno(r1)
}
return
}
func GetTcp6Table2(tcpTable PMIB_TCP6TABLE2, bufSize *uint32, order bool) (errcode error) {
r1, _, _ := syscall.Syscall(procGetTCP6Table2.Addr(), 3, uintptr(unsafe.Pointer(tcpTable)), uintptr(unsafe.Pointer(bufSize)), getUintptrFromBool(order))
if r1 != 0 {
errcode = syscall.Errno(r1)
}
return
}
func GetExtendedUdpTable(pUdpTable uintptr, pdwSize *uint32, bOrder bool, ulAf uint32, tableClass UDP_TABLE_CLASS, reserved uint32) (errcode error) {
r1, _, _ := syscall.Syscall6(procGetExtendedUDPTable.Addr(), 6, pUdpTable, uintptr(unsafe.Pointer(pdwSize)), getUintptrFromBool(bOrder), uintptr(ulAf), uintptr(tableClass), uintptr(reserved))
if r1 != 0 {
errcode = syscall.Errno(r1)
}
return
}
func GetExtendedTcpTable(pTcpTable uintptr, pdwSize *uint32, bOrder bool, ulAf uint32, tableClass TCP_TABLE_CLASS, reserved uint32) (errcode error) {
r1, _, _ := syscall.Syscall6(procGetExtendedTCPTable.Addr(), 6, pTcpTable, uintptr(unsafe.Pointer(pdwSize)), getUintptrFromBool(bOrder), uintptr(ulAf), uintptr(tableClass), uintptr(reserved))
if r1 != 0 {
errcode = syscall.Errno(r1)
}
return
}