This comment brought up this concern, and sums it up pretty well. Unfortunately it wasn't made into it's own issue.
To send and receive file descriptors in C, you need to interface with the libc cmsghdr struct, and you're supposed to do so via the CMSG_* macros which are defined in <sys/socket.h> in the C standard library.
I see that there is already a std.c.cmsghdr struct (see also: std.c.posix_cmsghdr, std.os.linux.cmsghdr).
But, there isn't a way to interface with this API in Zig (as far as I understand).
This comment explains some stuff as well on the topic.
I put together the list of the macros from <sys/socket.h>:
CMSG_DATA(): Defined in POSIX at least since Issue 6
CMSG_NXTHDR(): Defined in POSIX at least since Issue 6
CMSG_FIRSTHDR(): Defined in POSIX at least since Issue 6
CMSG_SPACE(): Defined in POSIX at least since Issue 8
CMSG_LEN(): Defined in POSIX at least since Issue 8
CMSG_ALIGN(): Linux Extension, since v2.1.15
Some further reading:
[This comment](https://github.com/ziglang/zig/pull/24603#issuecomment-3136040106) brought up this concern, and sums it up pretty well. Unfortunately it wasn't made into it's own issue.
To send and receive file descriptors in C, you need to interface with the libc `cmsghdr` struct, and you're supposed to do so via the `CMSG_*` macros which are defined in `<sys/socket.h>` in the C standard library.
I see that there is already a `std.c.cmsghdr` struct (see also: `std.c.posix_cmsghdr`, `std.os.linux.cmsghdr`).
But, there isn't a way to interface with this API in Zig (as far as I understand).
[This comment](https://github.com/ziglang/zig/pull/25118#issuecomment-3246571861) explains some stuff as well on the topic.
I put together the list of the macros from `<sys/socket.h>`:
- `CMSG_DATA()`: Defined in POSIX at least since Issue 6
- `CMSG_NXTHDR()`: Defined in POSIX at least since Issue 6
- `CMSG_FIRSTHDR()`: Defined in POSIX at least since Issue 6
- `CMSG_SPACE()`: Defined in POSIX at least since Issue 8
- `CMSG_LEN()`: Defined in POSIX at least since Issue 8
- `CMSG_ALIGN()`: Linux Extension, since v2.1.15
## Some further reading:
- [ZIG: GH: Comment that describes this issue](https://github.com/ziglang/zig/pull/24603#issuecomment-3136040106)
- [ZIG: An example of another user's Zig abstraction for using the `cmsg_hdr` struct](https://github.com/gdnsd/gdnsd/blob/3.99-alpha/gks/ancil.zig)
- [ZIG: GH: PR #25118](https://github.com/ziglang/zig/pull/25118#issuecomment-3246571861)
- [POSIX: ISSUE 6: socket.h](https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/socket.h.html)
- [POSIX: ISSUE 7: socket.h](https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/basedefs/sys_socket.h.html)
- [POSIX: ISSUE 8: socket.h](https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_socket.h.html)
- [LINUX: CMSG_ALIGN patch](https://ftp.funet.fi/index/Linux/kernel/v2.1/patch-html/patch-2.1.15/linux_include_linux_socket.h.html)
- [LINUX: v2.1.14: socket.h](https://elixir.bootlin.com/linux/2.1.14/source/include/linux/socket.h)
- [LINUX: v2.1.15: socket.h](https://elixir.bootlin.com/linux/2.1.15/source/include/linux/socket.h)
- [MUSL: socket.h](https://git.musl-libc.org/cgit/musl/plain/include/sys/socket.h)
- [GLIBC: socket.h](https://sourceware.org/git/gitweb.cgi?p=glibc.git;a=blob_plain;f=include/sys/socket.h;hb=HEAD)
- [RUST: cmsghdr](https://docs.rs/libc/latest/libc/struct.cmsghdr.html)