Description
sendmsg(2) and recvmsg(2) allow the exchange of out-of-band "ancillary data", such as file descriptors and errors. These messages are created and accessed using the CMSG_* macros (see the cmsg(3) man page). Some packages, such as erlang/OTP, use these messages to communicate file descriptors over unix domain sockets. The passage of file descriptors, using type SCM_RIGHTS, may require some special handling beyond simple copying, as queueing a file descriptor is actually storing a reference to the object being described, not the descriptor numbers themselves. (e.g. on a multi-process system, an fd written by one process may be read as a different fd by another process - yet both refer to the same object) Also, the writing of descriptors should count as a reference to the underlying object, as the descriptors may be closed after writing ancillary data containing them - while still allowing the receiving end to read open descriptors.
References:
https://www.man7.org/linux/man-pages/man3/cmsg.3.html
https://blog.cloudflare.com/know-your-scm_rights/