This project demonstrates examples of using control messages (ancillary data) in the context of interprocess communication. Control messages allow you to pass additional information along with your data when sending and receiving messages between processes or sockets.
Control messages are implemented using the cmsghdr
structure, which is part of the standard POSIX headers and is defined in <sys/socket.h>
.
- ✓ SCM_RIGHTS (0x01): Access rights (array of file descriptors)
- LU/SOCK_STREAM - UNIX/SOCK_DGRAM - UNIX/SOCK_SEQPACKET - UNIX
- ✓ SCM_TIMESTAMP (0x02): Timestamp (struct timeval)
- LU/SOCK_DGRAM - UNIX
- INET/SOCK_STREAM - IPPROTO_TCP/SOCK_DGRAM - IPPROTO_UDP
- INET6/SOCK_STREAM - IPPROTO_TCP/SOCK_DGRAM - IPPROTO_UDP
- ✓ SCM_CREDENTIALS (0x03): Process credentials (struct ucred)
- LU/SOCK_STREAM - UNIX/SOCK_DGRAM - UNIX/SOCK_SEQPACKET - UNIX
- × SCM_SECURITY (0x04): Security label
- NOT IMPLEMENTED
- × SCM_PIDFD (0x05): PID file descriptor (int)
- NOT IMPLEMENTED
- ✓ SCM_TIMESTAMPNS (0x24/0x40): Timestamp in nanoseconds (struct timespec)
- LU/SOCK_DGRAM - UNIX
- INET/SOCK_STREAM - IPPROTO_TCP/SOCK_DGRAM - IPPROTO_UDP
- INET6/SOCK_STREAM - IPPROTO_TCP/SOCK_DGRAM - IPPROTO_UDP
- ✓ SCM_TIMESTAMPING (0x25/0x41): Complex timestamps (struct scm_timestamping)
- INET/SOCK_STREAM - IPPROTO_TCP/SOCK_DGRAM - IPPROTO_UDP
- INET6/SOCK_STREAM - IPPROTO_TCP/SOCK_DGRAM - IPPROTO_UDP
- ✓ SCM_RIGHTS (0x01): Access rights (array of file descriptors)
- LU/SOCK_STREAM - UNIX/SOCK_DGRAM - UNIX
- ✓ SCM_RIGHTS (0x01): Access rights (array of file descriptors)
- LU/SOCK_STREAM - UNIX/SOCK_DGRAM - UNIX
- ✓ SCM_TIMESTAMP (0x02): Timestamp (struct timeval)
- INET/SOCK_DGRAM - IPPROTO_UDP
- INET6/SOCK_DGRAM - IPPROTO_UDP
- × SCM_CREDS (0x03): Process creds (struct cmsgcred)
- Unsupported by Apple
- ✓ SCM_TIMESTAMP_MONOTONIC (0x04): Timestamp (uint64_t)
- INET/SOCK_DGRAM - IPPROTO_UDP
- INET6/SOCK_DGRAM - IPPROTO_UDP
- ✓ SCM_RIGHTS (0x01): Access rights (array of file descriptors)
- LU/SOCK_STREAM - UNIX/SOCK_DGRAM - UNIX/SOCK_SEQPACKET - UNIX
- ✓ SCM_TIMESTAMP (0x02): Timestamp (struct timeval)
- INET/SOCK_DGRAM - IPPROTO_UDP
- INET6/SOCK_DGRAM - IPPROTO_UDP
- ✓ SCM_CREDS (0x03): Process creds (struct cmsgcred)
- LU/SOCK_STREAM - UNIX/SOCK_DGRAM - UNIX/SOCK_SEQPACKET - UNIX
- ✓ SCM_BINTIME (0x04): Timestamp (struct bintime)
- INET/SOCK_DGRAM - IPPROTO_UDP
- ✓ SCM_REALTIME (0x05): Timestamp (struct timespec)
- INET/SOCK_DGRAM - IPPROTO_UDP
- INET6/SOCK_DGRAM - IPPROTO_UDP
- ✓ SCM_MONOTONIC (0x06): Timestamp (struct timespec)
- INET/SOCK_DGRAM - IPPROTO_UDP
- INET6/SOCK_DGRAM - IPPROTO_UDP
- ✓ SCM_TIME_INFO * (0x07): Timestamp info
- Supported only with certain types of network devices on FreeBSD
- ✓ SCM_CREDS2 (0x08): Process creds (struct sockcred2)
- LU/SOCK_STREAM - UNIX/SOCK_DGRAM - UNIX/SOCK_SEQPACKET - UNIX
- ✓ SO_TS_REALTIME_MICRO (0x00): Microsecond resolution, realtime
- ✓ SO_TS_BINTIME (0x01): Sub-nanosecond resolution, realtime
- ✓ SO_TS_REALTIME (0x02): Nanosecond resolution, realtime
- ✓ SO_TS_MONOTONIC (0x03): Nanosecond resolution, monotonic
To explore the examples and their implementations, refer to the following links for detailed information:
- Linux: linux/socket.h, linux/socket.h
- Haiku: haiku/headers/posix/sys/socket.h
- XNU: apple-oss-distributions/xnu/bsd/sys/socket.h
- FreeBSD: freebsd/freebsd-src/sys/sys/socket.h
-
- Supported only with certain types of network devices on FreeBSD
-
- Driver support is only implemented for ConnectX4/5: https://reviews.freebsd.org/D12638
-
- Research:
For more information on each control message's behavior and usage, refer to the links provided for the corresponding