Skip to content
BSD syscall#337

svc · unix #337

sendfile

Transfers a file directly from a file descriptor to a socket without copying through user space.

Prototype

int sendfile(int fd, int s, off_t offset, off_t *nbytes, struct sf_hdtr *hdtr, int flags);

Returns: int

Arguments

NameTypeDirDescription
fdint-
sint-
offsetoff_t-
nbytesoff_t-
hdtrstruct sf_hdtr-
flagsint-

Version history

XNU tagmacOS#
xnu-1456.1.26macOS 10.6 Snow Leopard337
xnu-1699.24.8macOS 10.7 Lion337
xnu-2050.18.24macOS 10.8 Mountain Lion337
xnu-2422.115.4macOS 10.9 Mavericks337
xnu-2782.40.9macOS 10.10 Yosemite337
xnu-3247.1.106macOS 10.11 El Capitan337
xnu-3789.1.32macOS 10.12 Sierra337
xnu-4570.1.46macOS 10.13 High Sierra337
xnu-4903.221.2macOS 10.14 Mojave337
xnu-6153.11.26macOS 10.15 Catalina337
xnu-7195.50.7.100.1macOS 11.0 Big Sur337
xnu-8019.41.5macOS 12.0 Monterey337
xnu-8792.41.9macOS 13.0 Ventura337
xnu-10002.1.13macOS 14.0 Sonoma337
xnu-11215.1.10macOS 15.0 Sequoia337
xnu-11417.101.15macOS 15.4 Sequoia337
xnu-12377.1.9macOS 26.0 Tahoe337
xnu-10002.41.9337
xnu-10002.61.3337
xnu-10002.81.5337
xnu-10063.101.15337
xnu-10063.121.3337
xnu-10063.141.1337
xnu-11215.41.3337
xnu-11215.61.5337
xnu-11215.81.4337
xnu-11417.121.6337
xnu-11417.140.69337
xnu-12377.101.15337
xnu-12377.41.6337
xnu-12377.61.12337
xnu-12377.81.4337
xnu-1486.2.11337
xnu-1504.15.3337
xnu-1504.3.12337
xnu-1504.7.4337
xnu-1504.9.17337
xnu-1504.9.26337
xnu-1504.9.37337
xnu-1699.22.73337
xnu-1699.22.81337
xnu-1699.24.23337
xnu-1699.26.8337
xnu-1699.32.7337
xnu-2050.22.13337
xnu-2050.24.15337
xnu-2050.48.11337
xnu-2050.7.9337
xnu-2050.9.2337
xnu-2422.1.72337
xnu-2422.100.13337
xnu-2422.110.17337
xnu-2422.90.20337
xnu-2782.1.97337
xnu-2782.10.72337
xnu-2782.20.48337
xnu-2782.30.5337
xnu-3247.10.11337
xnu-3248.20.55337
xnu-3248.30.4337
xnu-3248.40.184337
xnu-3248.50.21337
xnu-3248.60.10337
xnu-3789.21.4337
xnu-3789.31.2337
xnu-3789.41.3337
xnu-3789.51.2337
xnu-3789.60.24337
xnu-3789.70.16337
xnu-4570.20.62337
xnu-4570.31.3337
xnu-4570.41.2337
xnu-4570.51.1337
xnu-4570.61.1337
xnu-4570.71.2337
xnu-4903.231.4337
xnu-4903.241.1337
xnu-4903.270.47337
xnu-6153.101.6337
xnu-6153.121.1337
xnu-6153.141.1337
xnu-6153.41.3337
xnu-6153.61.1337
xnu-6153.81.5337
xnu-7195.101.1337
xnu-7195.121.3337
xnu-7195.141.2337
xnu-7195.60.75337
xnu-7195.81.3337
xnu-8019.61.5337
xnu-8019.80.24337
xnu-8020.101.4337
xnu-8020.121.3337
xnu-8020.140.41337
xnu-8792.61.2337
xnu-8792.81.2337
xnu-8796.101.5337
xnu-8796.121.2337
xnu-8796.141.3337

Notes

macOS sendfile has the BSD signature (in_fd, out_socket, offset, *len, *hdtr, flags) — not the Linux one. The kernel uses UBC (Unified Buffer Cache) pages and, for TCP, splices them into the send queue via sosend_list, which can engage TSO (TCP Segmentation Offload) on supported NICs. The hdtr argument lets callers attach headers and trailers in the same atomic operation, useful for HTTP responses.

Detection

Bytes still pass through NEFilterDataProvider just like sendto. File-side activity (the read) is invisible to ES too because the data never re-enters user space.

Related APIs

writesendmsgreadmmap