Skip to content

Instantly share code, notes, and snippets.

@madwizard
Created April 17, 2019 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madwizard/05fdbf3f128f883bec90c07648e585ea to your computer and use it in GitHub Desktop.
Save madwizard/05fdbf3f128f883bec90c07648e585ea to your computer and use it in GitHub Desktop.
Mapping C struct to go
func wirelessScan() int {
p := C.malloc(unsafe.Pointer(C.wireless_scan_head{}))
defer C.free(p)
iface := C.CString("wlp4s0")
sk := iwSocketsOpen()
weVersion := getKernelWEVersion()
ret := int(C.iw_process_scan(_Ctype_int(sk), iface, _Ctype_int(weVersion), unsafe.Pointer(p)))
return ret
}
Returned error:
 dwojslaw  ~  GolandProjects  gowifiscanner  go run main.go wifi.go
# command-line-arguments
./wifi.go:36:39: cannot convert _Ctype_struct_wireless_scan_head literal (type _Ctype_struct_wireless_scan_head) to type unsafe.Pointer
./wifi.go:43: cannot use unsafe.Pointer(p) (type unsafe.Pointer) as type *_Ctype_struct_wireless_scan_head in argument to func literal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment