rust-lang / rust-lang/libc

The sockaddr_in is missing documentation of the `sin_len` field.

Open
#3,414 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-API-request
Dominant language
Rust
Stars
2.6k
Forks
1.3k
Avg merge
1d 22h
Merged PRs (30d)
69

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the sockaddr_in documentation on docs.rs with the platform definitions referenced by the man7 sockaddr page, focusing on the undocumented sin_len field. Document what the field is and when it applies, then verify that the generated sockaddr_in documentation explains it accurately.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.