锈libc :: setsockopt强制转换为c_void

时间:2018-11-25 15:54:53

标签: rust libc setsockopt

我正尝试致电setsockopt,但无法找出对c_void的演员表。 IP_HDRINCL不在nixsocket的板条箱中,因此我必须使用libc。我以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 个答案:

答案 0 :(得分:-2)

trueval更改为u8即可使代码正常工作。