Print this page
13175 Add support for IP_RECVTOS
13182 CMSG_ macros should have man pages
Change-ID: I784aa36cfd3c17e3cccbf1fd329fa7e69b663ef9
@@ -1316,12 +1316,28 @@
if (oldflg)
continue;
cmsg->cmsg_level = tohp->level;
cmsg->cmsg_type = tohp->name;
- cmsg->cmsg_len = (socklen_t)(_TPI_TOPT_DATALEN(tohp) +
- sizeof (struct cmsghdr));
+ cmsg->cmsg_len = (socklen_t)sizeof (struct cmsghdr);
+ if (tohp->level == IPPROTO_IP &&
+ (tohp->name == IP_RECVTOS ||
+ tohp->name == IP_RECVTTL)) {
+ /*
+ * The data for these is a uint8_t but, in
+ * order to maintain alignment for any
+ * following TPI primitives in the message,
+ * there will be some trailing padding bytes
+ * which are included in the TPI_TOPT_DATALEN.
+ * For these types, we set the cmsg_len
+ * explicitly to the correct value.
+ */
+ cmsg->cmsg_len += (socklen_t)sizeof (uint8_t);
+ } else {
+ cmsg->cmsg_len +=
+ (socklen_t)(_TPI_TOPT_DATALEN(tohp));
+ }
/* copy content to control data part */
bcopy(&tohp[1], CMSG_CONTENT(cmsg),
CMSG_CONTENTLEN(cmsg));
}