unix-ancillary
Safe, ergonomic Unix socket ancillary data (SCM_RIGHTS file descriptor passing) for Rust.
Features
- Safe
OwnedFd/BorrowedFdAPI — no raw file descriptors in the public API - Automatic cleanup — received FDs are
OwnedFd, closed on drop - macOS fd-leak protection — detects kernel-level truncation and closes leaked FDs
- Ergonomic extension traits —
send_fds()/recv_fds()onUnixStreamandUnixDatagram
Quick Start
use UnixStream;
use UnixStreamExt;
let = pair.unwrap;
// Send a file descriptor
let file = open.unwrap;
tx.send_fds.unwrap;
// Receive it
let = rx..unwrap;
assert_eq!;
assert_eq!;
// fds[0] is an OwnedFd — automatically closed on drop
Low-Level API
use ;
use IoSlice;
use AsFd;
let mut buf = ;
let mut ancillary = new;
ancillary.add_fds.unwrap;
Platform Support
- Linux — full support with
MSG_CMSG_CLOEXEC - macOS — supported with
fcntlCLOEXEC fallback + fd-leak protection - FreeBSD, OpenBSD, NetBSD, DragonFly — supported with
MSG_CMSG_CLOEXEC
License
MIT