2
votes

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
From the code snippets visible in the link it looks like you should be able to do it like this (*C.struct_sockaddr)(unsafe.Pointer(&sa)), although I haven't tested it myself so I'm not 100% sure. - mkopriva

1 Answers

2
votes

Thanks mkopriva!

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