Calling C function that requires sockaddr

穿精又带淫゛_ 提交于 2021-02-04 16:27:09

问题


I have a C function that takes a sockaddr pointer.

I've created a syscall.RawSockaddrInet4 object, but I cannot figure out how to cast the address of the object to a C.sockaddr pointer.

I've tried this, (*syscall.RawSockaddr)(unsafe.Pointer(&sa)), but I get an error:

cannot use (*syscall.RawSockaddr)(unsafe.Pointer(&sa)) (type *syscall.RawSockaddr) as type *C.struct_sockaddr in argument to _Cfunc_lib_connect

Any ideas would be much appreciated!

int lib_connect( int sock, enum lib_sock_type type, const struct sockaddr* srv, int srv_sz);


回答1:


Thanks mkopriva!

(*C.struct_sockaddr)(unsafe.Pointer(&sa))



来源:https://stackoverflow.com/questions/47243350/calling-c-function-that-requires-sockaddr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!