[ Team LiB ] |
22.3 Datagram TruncationOn BSD-derived systems, when a UDP datagram arrives that is larger than the application's buffer, recvmsg sets the MSG_TRUNC flag in the msg_flags member of the msghdr structure (Figure 14.7). All Berkeley-derived implementations that support the msghdr structure with the msg_flags member provide this notification.
Unfortunately, not all implementations handle a larger-than-expected UDP datagram in this fashion. There are three possible scenarios:
Since there are such variations in how implementations handle datagrams that are larger than the application's receive buffer, one way to detect the problem is to always allocate an application buffer that is one byte greater than the largest datagram the application should ever receive. If a datagram is ever received whose length equals this buffer, consider it an error. |
[ Team LiB ] |