[PATCH] fix msghdr for 64bit platform (Was: status of 0.9.29)

Atsushi Nemoto anemo at mba.ocn.ne.jp
Thu Oct 26 15:36:19 UTC 2006


On Wed, 18 Oct 2006 13:57:45 +0900 (JST), Atsushi Nemoto <anemo at mba.ocn.ne.jp> wrote:
> It looks due to mismatch of struct msghdr.
...
> On 64-bit environment, the size of msg_namelen seems 4 for all, but
> the size of msg_iovlen and msg_controllen is 8 for kernel and glibc, 4
> for uClibc.
> 
> If I copied struct msghdr from glibc, "ip addr" works well.
> 
> But, there is a note in libc/sysdeps/linux/common/bits/socket.h.
> 
> /* Note: do not change these members to match glibc; these match the
>    SuSv3 spec already (e.g. msg_iovlen/msg_controllen).
>    http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/socket.h.html */
> 
> Then ... what should we do?

Then how about attached patch?  It would solve the problem on 64-bit
platforms.

Or we might be able to do something like this and make
sendmsg/recvmsg wrappers which clear zeropad fields, but I think it is
not worth to do so ...

#if __WORDSIZE == 64 && __BYTE_ORDER == __BIG_ENDIAN
    int zeropad;
#endif
    int msg_iovlen;		/* Number of elements in the vector.  */
#if __WORDSIZE == 64 && __BYTE_ORDER == __LITTLE_ENDIAN
    int zeropad;
#endif

---
Atsushi Nemoto
-------------- next part --------------
Index: libc/sysdeps/linux/common/bits/socket.h
===================================================================
--- libc/sysdeps/linux/common/bits/socket.h	(revision 16441)
+++ libc/sysdeps/linux/common/bits/socket.h	(working copy)
@@ -215,16 +215,26 @@
 /* Note: do not change these members to match glibc; these match the
    SuSv3 spec already (e.g. msg_iovlen/msg_controllen).
    http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/socket.h.html */
+/* Note: but linux kernel use __kernel_size_t (which is 8byte on 64bit
+   platforms) for msg_iovlen/msg_controllen */
 struct msghdr
   {
     void *msg_name;		/* Address to send to/receive from.  */
     socklen_t msg_namelen;	/* Length of address data.  */
 
     struct iovec *msg_iov;	/* Vector of data to send/receive into.  */
+#if __WORDSIZE == 64
+    size_t msg_iovlen;		/* Number of elements in the vector.  */
+#else
     int msg_iovlen;		/* Number of elements in the vector.  */
+#endif
 
     void *msg_control;		/* Ancillary data (eg BSD filedesc passing). */
+#if __WORDSIZE == 64
+    size_t msg_controllen;	/* Ancillary data buffer length.  */
+#else
     socklen_t msg_controllen;	/* Ancillary data buffer length.  */
+#endif
 
     int msg_flags;		/* Flags on received message.  */
   };
Index: libc/sysdeps/linux/mips/bits/socket.h
===================================================================
--- libc/sysdeps/linux/mips/bits/socket.h	(revision 16441)
+++ libc/sysdeps/linux/mips/bits/socket.h	(working copy)
@@ -219,10 +219,18 @@
     socklen_t msg_namelen;	/* Length of address data.  */
 
     struct iovec *msg_iov;	/* Vector of data to send/receive into.  */
+#if __WORDSIZE == 64
+    size_t msg_iovlen;		/* Number of elements in the vector.  */
+#else
     int msg_iovlen;		/* Number of elements in the vector.  */
+#endif
 
     void *msg_control;		/* Ancillary data (eg BSD filedesc passing). */
+#if __WORDSIZE == 64
+    size_t msg_controllen;	/* Ancillary data buffer length.  */
+#else
     socklen_t msg_controllen;	/* Ancillary data buffer length.  */
+#endif
 
     int msg_flags;		/* Flags on received message.  */
   };


More information about the uClibc mailing list