Hi,
I have been trying to abstract libc::bind to reduce complexity and use directly in the programs.
Any idea how to get past this error? Any help is appreciated.
error[E0606]: casting &mut sockaddr_un
as *const sockaddr
is invalid
--> src/socket.rs:54:30
|
54 | ... &mut serv_addr as *const libc::sockaddr,
Code is below,
pub fn unix_tcp_server(&mut self, path : &mut String, n_conn : u32) -> i32 {
let mut res : i32 = -1;
unsafe {
self.fd = libc::socket(libc::AF_UNIX, libc::SOCK_STREAM, 0);
if self.fd < 0 {
res = -1;
}
let mut serv_addr = libc::sockaddr_un {
sun_family : libc::AF_INET as u16,
sun_path : [0; 108],
};
copy_str_to_buf(path, &mut serv_addr.sun_path);
res = libc::bind(self.fd,
&mut serv_addr as *const libc::sockaddr,
mem::size_of::<libc::sockaddr_un>().try_into().unwrap());
}
res
}