rust libc::setsockopt cast to c_void

497 views Asked by At

I'm trying to call setsockopt but can't figure out the cast to c_void. IP_HDRINCL isn't in nix or socket crates, so I have to use libc. I'm following the example of How to set the socket option SO_REUSEPORT in Rust?

let trueval: c_int = 1;
let ret = setsockopt(mysocket, IPPROTO_IP, IP_HDRINCL, &trueval as *const _ as *const c_void, mem::size_of_val(&trueval) as socklen_t);
error: expected expression, found keyword `const`
  --> src/igmp.rs:30:97
   |
30 |         let ret = setsockopt(mysocket, IPPROTO_IP, IP_HDRINCL, &trueval as *const _ *const c_void, mem::size_of_val(&trueval) as socklen_t);
   |                                                                                      ^^^^^ expected expression
1

There are 1 answers

0
ruckc On

Changing trueval to type u8 allows the code to work.