SENDFD(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

okay bestie, welcome to sendfd(3) β€” straight out of the Library Functions Manual β€” and it’s literally the page for sendfd and recvfd, the little duo that passes file descriptors along Unix domain sockets. no cap, it’s giving kernel handoff magic ✨

✨ NAME ✨

sendfd, recvfd β€” pass file descriptors along Unix domain sockets πŸ¦‹

πŸ¦‹ SYNOPSIS πŸ¦‹

#include <u.h>

#include <libc.h>

int  sendfd(int socket, int fd)

int  recvfd(int socket)

πŸ’… DESCRIPTION πŸ’…

okay so here’s the vibe: recvfd and sendfd can be used to pass an open file descriptor over a Unix domain socket from one process to another. πŸ’…

and since pipe(3) is implemented with socketpair(2) instead of pipe(2), socket can be a file descriptor obtained from pipe(3). iykyk πŸ‘‘

sendfd sends the file descriptor fd along the socket to a process calling recvfd on the other end. literally passing the fd handoff 🫢

it is assumed that the two sides have coordinated and agreed to transfer a file descriptor already, so that the sendfd is met with a recvfd instead of an ordinary read. like, both sides have to be in on the plan fr fr 😭

the file descriptor number may change on its way between processes, but the kernel structure it represents will not. so the number might do a little glow-up, but the kernel structure it represents stays exactly what it is πŸ’€

πŸŽ€ SOURCE πŸŽ€

/src/lib9/sendfd.c β€” that’s where this lives, periodt πŸŽ€

🌈 SEE ALSO 🌈


πŸ’– and that’s the whole page! the footer is just SENDFD(3) β€” no extra version or date listed, so consider this your cute sign-off. mwah πŸ’–