问题
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