Subject
socket2 is a Rust library for creating and configuring sockets with finer-grained control than the standard library exposes. It is owned by the rust-lang organisation. The crate's headline type, Socket, is a thin owned-handle wrapper over std::os::fd::OwnedFd on Unix-likes / WASI and std::os::windows::io::OwnedSocket on Windows. Around that, the crate exposes domain/type/protocol newtype constants, the SockAddr/SockAddrStorage types over the platform's sockaddr_storage, a SockRef borrow that re-uses the API against externally-owned descriptors, TcpKeepalive parameters, and the MsgHdr/MsgHdrMut/MaybeUninitSlice types used for the scatter-gather APIs. The crate is no-build-script and exports the all feature to opt into platform-specific extras.
The crate is by design a syscall-level wrapper. It does not implement any network protocol, validation, or buffering of its own; everything routes to a single corresponding libc or WinSock entry point.
Methodology
The published crate was downloaded by openvet audit new and unpacked into contents/; the upstream Git repository (https://github.com/rust-lang/socket2) was cloned into vcs/ and checked out at the commit recorded in .cargo_vcs_info.json.
Tools used:
openvet audit (workspace creation, annotations, claims, findings, dependency narratives, report).
diff -rq to compare contents/src/ against vcs/src/.
grep to enumerate unsafe keyword sites (~240 total), extern "C" declarations (none in this crate), and standard-library I/O patterns outside socket APIs (std::env, std::process::Command, std::fs::File/OpenOptions, std::thread::spawn, tokio, reqwest, cryptography crates).
wc -l for line counts.
Reading: src/lib.rs in full; src/sockref.rs in full; head and key sections of src/sockaddr.rs (around as_socket and the From<SocketAddr*> impls); src/socket.rs head and around Socket::from_raw; the syscall! macro and its surrounding type definitions in both src/sys/unix.rs (line 345) and src/sys/windows.rs (line 149); Windows-specific init (std::sync::Once-gated init(), src/sys/windows.rs:280-289); the getsockopt/setsockopt definitions (unix.rs:1358-1391, windows.rs:874-900); the OwnedFd/OwnedSocket type aliases (unix.rs:929-930, windows.rs:291). The integration-test file (vcs/tests/socket.rs, ~1970 lines) was surveyed for shape; it covers TCP and UDP socket creation, every option setter/getter, Unix domain sockets, and platform-conditional behaviour.
Results
The diff between the published contents/src/ and the upstream Git checkout shows that all source files match byte-for-byte. The Cargo.toml differences are limited to cargo's standard normalisation. The published artefact excludes .github/, tests/, and other repository-only files via the include = [...] list.
The crate ships no binary artefacts (justifying has-binaries), no build.rs (justifying has-build-exec), and no installer hook (justifying has-install-exec). The [lib] section sets no proc-macro = true. There are no direct extern "C" blocks; every FFI call goes through libc (unix) or windows_sys::Win32::Networking::WinSock (windows). Both are external crates not in scope for this audit.
unsafe is pervasive (~240 occurrences) but disciplined. The dominant pattern is the syscall! macro in each back-end, which wraps a single libc::$fn(...) or winsock::$fn(...) call in an unsafe { ... } block and translates the C error convention into an io::Result. Beyond that, unsafe appears at: (1) the sockaddr family-tagged casts in src/sockaddr.rs (only after ss_family is checked); (2) MaybeUninit::assume_init after a syscall has filled the storage (with len cross-checked); (3) the Socket::from_raw_fd/from_raw_socket calls in sockref.rs:80-111, paired with an assert! that the raw value is in range; (4) mem::zeroed::<sockaddr_storage>() which is sound because sockaddr_storage is a C struct of integer fields with no invalid bit patterns. Each non-trivial unsafe block carries a // SAFETY: comment. The crate's MSRV is 1.70 and OwnedFd/OwnedSocket are used for lifetime management, so the historical "close-on-drop fd safety" surface is delegated to the standard library. Together this is the basis for uses-unsafe, unsafe-safe, unsafe-documented, and unsafe-minimal.
The crate is intrinsically network: Socket::new, bind, connect, listen, accept, send, recv and dozens of option setters are the public API. Inputs (addresses, options, buffers) are passed straight to the kernel without crate-side validation; the kernel performs whatever validation it does. The crate does not introduce a network-validation surface of its own, supporting uses-network and network-safe. The crate does not pick or enforce a "secure protocol by default" — it exposes raw socket primitives — so network-secure is not asserted; this is the natural shape of a primitives library.
Filesystem usage is limited to AF_UNIX socket paths, which the crate accepts as &Path/&[u8] and copies into the sun_path field of sockaddr_un (src/sys/unix.rs:703-741). The crate does not open, read, or write files itself; it merely forwards the path to bind(2). No traversal-relevant logic is introduced; the path is the caller's responsibility. Supports uses-filesystem and filesystem-safe.
No use of std::env, std::process::Command, std::fs::*, thread spawning, cryptography, JIT, or interpreters was found. Justifies uses-environment, uses-exec, uses-crypto, uses-jit, and uses-interpreter. A single std::sync::Once is used in src/sys/windows.rs to trigger libstd's WinSock initialisation by binding a dummy UdpSocket; this is not a concurrency primitive the crate implements or maintains, just a one-shot init guard. Justifies uses-concurrency.
Per the registry-specific guidance, the crate does not itself implement any parser, interpreter, JIT, protocol, data structure, algorithm, cryptographic primitive, or concurrency primitive; the corresponding impl-* claims (impl-parser, impl-interpreter, impl-jit, impl-protocol, impl-datastructure, impl-algorithm, impl-crypto, impl-concurrency) are all false. The crate is a kernel binding, not an implementation.
Tests: a single ~1970-line integration test (tests/socket.rs) lives upstream and is shipped neither in the .crate (excluded via the manifest's include list) nor referenced in the [[test]] section of the published Cargo.toml. CI exercises it on every platform the crate claims to support (per vcs/.github/). No #[cfg(test)] unit-test modules are present in src/, and no fuzz harness or property-test harness ships with the crate, justifying has-unit-tests = false, has-integration-tests = true (the file exists upstream and runs in CI), has-fuzz-tests = false, and has-property-tests = false. The integration tests run the actual socket APIs against the host kernel, which is what supports unsafe-tested.
No findings were recorded. The crate is authored by rust-lang maintainers, matches its upstream commit byte-for-byte, and contains no behaviour at odds with its documented purpose. This is the basis for is-benign.
Conclusion
socket2 is a mature, well-scoped FFI binding to the socket APIs of every supported platform. Its unsafe surface is large (because that's what binding a C-shaped API entails) but is structured around a single syscall! macro per back-end, with the lifetime-of-fd concerns delegated to libstd's OwnedFd/OwnedSocket. The crate does not itself implement any protocol or attempt validation; that's the caller's job. No findings were observed.