Open
Description
The following code
use libc::{socket, bind, accept, listen, connect, close};
use libc::{sockaddr_in, sockaddr, in_addr};
use libc::{AF_INET, SOCK_STREAM, INADDR_ANY};
use std::os::fd::RawFd;
fn main() {
unsafe {
let sock:RawFd = socket(AF_INET, SOCK_STREAM, 0);
let servaddr = sockaddr_in{sin_zero:[0;8],
sin_family:AF_INET as u8,
sin_port:u16::from_le_bytes((12001 as u16).to_ne_bytes()),
sin_addr:in_addr{s_addr:INADDR_ANY}
};
close(sock);
}
}
Fails to compile with
error[E0063]: missing field `sin_len` in initializer of `sockaddr_in`
--> src/main.rs:10:24
|
10 | let servaddr = sockaddr_in{sin_zero:[0;8],
| ^^^^^^^^^^^ missing `sin_len`
For more information about this error, try `rustc --explain E0063`.
warning: `hello_world` (bin "hello_world") generated 2 warnings
error: could not compile `hello_world` (bin "hello_world") due to previous error; 2 warnings emitted
In https://docs.rs/libc/latest/libc/struct.sockaddr_in.html , there is no documentation of the sin_len
field of the struct.
Also i have never heard of this field in C types themselves for sockaddr_in
, https://man7.org/linux/man-pages/man3/sockaddr.3type.html so unclear what this field is or does.