为什么 recvmsg 不接受 MSG_CTRUNC 作为标志?

为什么 recvmsg 不接受 MSG_CTRUNC 作为标志?

根据man 2 recv recvmsg可能返回MSG_TRUNC

   MSG_TRUNC
          indicates that the trailing portion of a datagram was dis‐
          carded because the datagram was larger than the buffer sup‐
          plied.

因为有时我们想知道我们需要分配的缓冲区的大小MSG_TRUNC也可以用作flags字段中的参数

   MSG_TRUNC (since Linux 2.2)
          For raw (AF_PACKET), Internet datagram (since Linux
          2.4.27/2.6.8), netlink (since Linux 2.6.22), and UNIX datagram
          (since Linux 3.4) sockets: return the real length of the
          packet or datagram, even when it was longer than the passed
          buffer.

文件还指出recvmsg也可能会返回MSG_CTRUNC

   MSG_CTRUNC
          indicates that some control data were discarded due to lack of
          space in the buffer for ancillary data.

然而没有办法获得辅助数据的真实长度。难道recvmsg不应该接受MSG_CTRUNC以便我们可以获得辅助数据的实际大小吗?

相关内容