Diego Nieto Cid, le mer. 01 janv. 2025 20:07:04 +0000, a ecrit: > On Wed, Jan 01, 2025 at 06:51:47PM +0100, Samuel Thibault wrote: > > > /* Structure used for storage of ancillary data object information. > > > */ > > > struct cmsghdr > > > { > > > socklen_t cmsg_len; /* Length of data in cmsg_data plus > > > length > > > of cmsghdr structure. */ > > > > That's the correct type according to posix: > > > > ./basedefs/sys_socket.h.html:<tt>socklen_t cmsg_len </tt> Data byte > > count, including the <b>cmsghdr</b>. <tt> > > > > Ok, but
I was only answering about the cmsg_len type, I hadn't taken the time to look at the rest yet. > we are giving unaligned data pointers with the current implementation > of CMSG_DATA. Indeed, that's a concern that we need to fix. The code dates from BSD 4.4, which probably hadn't been exposed to 64b systems yet. > GLib has the following code to parse control messages > > control_message = g_socket_control_message_deserialize (cmsg->cmsg_level, > cmsg->cmsg_type, > cmsg->cmsg_len - ((char *)CMSG_DATA (cmsg) - (char > *)cmsg), > > the third parameter is the size of the ancillary data. And CMSG_DATA should > align the header structure size for it to work (bacause cmsg_len was computed > with CMSG_LEN which aligns the header). Indeed. And the whole data has to be aligned anyway. It's actually the very definition of __cmsg_data which is bogus, it can't be right with 64b ports. > Something like the definition below could work, (except for when felxarr are > available): > > #define CMSG_DATA(cmsg) ((unsigned char *) (cmsg) + (CMSG_ALIGN (sizeof > (struct cmsghdr)))) Yes, that's the more modern definition on BSDs. I'm pushing a fix on glibc master. Thanks! Samuel