我正尝试致电setsockopt
,但无法找出对c_void
的演员表。 IP_HDRINCL
不在nix
或socket
的板条箱中,因此我必须使用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
答案 0 :(得分:-2)
将trueval
更改为u8
即可使代码正常工作。