Python 3.3+Linux · macOSsocketfunction
socket.CMSG_LEN()
file descriptors and ancillary data
Returns the length of one ancillary data item without trailing padding, for use with sendmsg and recvmsg.
Syntax
socket.CMSG_LEN(length) -> int
The value is platform-specific (20 for 4 bytes on Linux x86-64), so compute it rather than hard-coding a number. For a recvmsg buffer size portable code uses CMSG_SPACE, not CMSG_LEN: with several items CMSG_LEN ignores padding, the data gets truncated (MSG_CTRUNC flag) and the passed descriptors are lost.
Examples
import socket
print(socket.CMSG_LEN(4)) # → ? 20 на Linux x86-64
print(socket.CMSG_LEN(4) <= socket.CMSG_SPACE(4)) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy