GSocket: define CMSG_LEN and CMSG_SPACE if the system doesn't
authorDan Winship <danw@gnome.org>
Thu, 25 Feb 2010 16:40:31 +0000 (11:40 -0500)
committerDan Winship <danw@gnome.org>
Fri, 23 Apr 2010 16:38:33 +0000 (12:38 -0400)
https://bugzilla.gnome.org/show_bug.cgi?id=589989

gio/gnetworkingprivate.h

index 4477032..7c0fef0 100644 (file)
 #define _PATH_RESCONF "/etc/resolv.conf"
 #endif
 
+#ifndef CMSG_LEN
+/* CMSG_LEN and CMSG_SPACE are defined by RFC 2292, but missing on
+ * some older platforms.
+ */
+#define CMSG_LEN(len) ((size_t)CMSG_DATA((struct cmsghdr *)NULL) + (len))
+
+/* CMSG_SPACE must add at least as much padding as CMSG_NXTHDR()
+ * adds. We overestimate here.
+ */
+#define ALIGN_TO_SIZEOF(len, obj) (((len) + sizeof (obj) - 1) & ~(sizeof (obj) - 1))
+#define CMSG_SPACE(len) ALIGN_TO_SIZEOF (CMSG_LEN (len), struct cmsghdr)
 #endif
 
 G_BEGIN_DECLS