BSD syscall#28
svc · unix #28
sendmsg
Sends a message together with optional ancillary control data using a scatter-gather buffer.
Prototype
int sendmsg(int s, caddr_t msg, int flags);Returns: int
Arguments
| Name | Type | Dir | Description |
|---|---|---|---|
| s | int | - | |
| msg | caddr_t | - | |
| flags | int | - |
Version history
| XNU tag | macOS | # |
|---|---|---|
| xnu-1456.1.26 | macOS 10.6 Snow Leopard | 28 |
| xnu-1486.2.11 | — | 28 |
| xnu-1504.15.3 | — | 28 |
| xnu-1504.3.12 | — | 28 |
| xnu-1504.7.4 | — | 28 |
| xnu-1504.9.17 | — | 28 |
| xnu-1504.9.26 | — | 28 |
| xnu-1504.9.37 | — | 28 |
Examples
Pass a file descriptor over AF_UNIX
char buf[CMSG_SPACE(sizeof(int))] = {0};
struct iovec iov = { .iov_base = "x", .iov_len = 1 };
struct msghdr msg = { .msg_iov = &iov, .msg_iovlen = 1,
.msg_control = buf, .msg_controllen = sizeof(buf) };
struct cmsghdr *c = CMSG_FIRSTHDR(&msg);
c->cmsg_level = SOL_SOCKET; c->cmsg_type = SCM_RIGHTS;
c->cmsg_len = CMSG_LEN(sizeof(int));
*(int *)CMSG_DATA(c) = fd_to_pass;
sendmsg(sock, &msg, 0);Notes
Mirror of recvmsg on the send side. It is the only entry point that can attach SCM_RIGHTS (file-descriptor passing) on AF_UNIX, set IP_PKTINFO source addresses, or carry NECP_CLIENT_PARAMETER cmsgs that bind a UDP packet to a specific Network.framework path. msghdr.msg_flags is ignored on input; only the iov, cmsg, and destination matter.
Detection
ES has no sendmsg event. NEFilterDataProvider sees payload bytes; descriptor passing via SCM_RIGHTS can be inferred by comparing PROC_PIDFDSOCKETINFO snapshots across peers.
Related APIs
sendtosendmsg_xrecvmsgsocketpairsetsockopt