Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error syscall GetTcpTable2, need your help #58

Closed
tinycedar opened this issue Jun 20, 2016 · 1 comment
Closed

Error syscall GetTcpTable2, need your help #58

tinycedar opened this issue Jun 20, 2016 · 1 comment

Comments

@tinycedar
Copy link

tinycedar commented Jun 20, 2016

I am new to windows programming and wanna syscall GetTcpTable2 by Golang, but error occurs on calling it, could you help me figure it out, so appreciated if you could help.

package main

import (
    "fmt"
    "syscall"
    "unsafe"
)

type (
    DWORD uint32
)

type TCP_CONNECTION_OFFLOAD_STATE int

const (
    TcpConnectionOffloadStateInHost     TCP_CONNECTION_OFFLOAD_STATE = 0
    TcpConnectionOffloadStateOffloading TCP_CONNECTION_OFFLOAD_STATE = 1
    TcpConnectionOffloadStateOffloaded  TCP_CONNECTION_OFFLOAD_STATE = 2
    TcpConnectionOffloadStateUploading  TCP_CONNECTION_OFFLOAD_STATE = 3
    TcpConnectionOffloadStateMax        TCP_CONNECTION_OFFLOAD_STATE = 4
)

type MIB_TCPROW2 struct {
    dwState        DWORD
    dwLocalAddr    DWORD
    dwLocalPort    DWORD
    dwRemoteAddr   DWORD
    dwRemotePort   DWORD
    dwOwningPid    DWORD
    dwOffloadState TCP_CONNECTION_OFFLOAD_STATE
}

type MIB_TCPTABLE2 struct {
    dwNumEntries DWORD
    table        []MIB_TCPROW2
}

func main() {
    call := syscall.NewLazyDLL("Iphlpapi.dll")
    var table MIB_TCPTABLE2 = MIB_TCPTABLE2{}
    getTcpTable2 := call.NewProc("GetTcpTable2")
    bbb := true
    getTcpTable2.Call(uintptr(unsafe.Pointer(&table)), unsafe.Sizeof(table), uintptr(unsafe.Pointer(&bbb)))

    fmt.Println(table)
}

Error Log:

$ go run getTcpTable.go
Exception 0xc0000005 0x0 0x20 0x7ffe96f4b7a9
PC=0x7ffe96f4b7a9

syscall.Syscall(0x7ffe96f61de0, 0x3, 0xc08202fef8, 0x20, 0xc08202fe57, 0xc08201c000, 0x0, 0xc082008140)
        D:/Program Files/go/src/runtime/syscall_windows.go:163 +0x5c
syscall.(*Proc).Call(0xc08200a780, 0xc08202fe58, 0x3, 0x3, 0x30, 0x4f98e0, 0x0, 0x0)
        D:/Program Files/go/src/syscall/dll_windows.go:149 +0x4a6
syscall.(*LazyProc).Call(0xc082007fb0, 0xc08202fe58, 0x3, 0x3, 0x6540a8, 0x48ab89, 0x0, 0x0)
        D:/Program Files/go/src/syscall/dll_windows.go:300 +0x6d
main.main()
        C:/Users/hzlinqien/Desktop/getTcpTable.go:43 +0x1c2
rax     0x2
rbx     0x7dbf2c
rcx     0x7dbf20
rdi     0x7dd04c
rsi     0x7d68b0
rbp     0x4c
rsp     0x8fd10
r8      0x1
r9      0x20
r10     0xc08202fef8
r11     0xffff
r12     0x0
r13     0x5434be
r14     0x0
r15     0x1
rip     0x7ffe96f4b7a9
rflags  0x10246
cs      0x33
fs      0x53
gs      0x2b
exit status 2
@tinycedar
Copy link
Author

I've figured it out, thanks anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant