fix FreeBSD support
authorPetr Salinger <Petr.Salinger@seznam.cz>
Mon, 7 Jul 2008 15:57:37 +0000 (17:57 +0200)
committerJulien Danjou <julien@danjou.info>
Mon, 7 Jul 2008 15:57:37 +0000 (17:57 +0200)
The GNU/kFreeBSD (and BSDs in general) have a different
layout of struct sockaddr, sockaddr_in, sockaddr_un ...

The first member do not have to be "sa_family",
they also have "sa_len" field.

Signed-off-by: Julien Danjou <julien@danjou.info>
configure.ac
src/xcb_util.c

index 91f7ae5..8b8cbdf 100644 (file)
@@ -70,6 +70,14 @@ AC_HEADER_STDC
 AC_SEARCH_LIBS(getaddrinfo, socket)
 AC_SEARCH_LIBS(connect, socket)
 
+dnl check for the sockaddr_un.sun_len member
+AC_CHECK_MEMBER([struct sockaddr_un.sun_len],
+               [AC_DEFINE(HAVE_SOCKADDR_SUN_LEN,1,[Have the sockaddr_un.sun_len member.])],
+               [],
+               [ #include <sys/types.h>
+                 #include <sys/un.h>
+               ])
+                                                                                                                                               
 xcbincludedir='${includedir}/xcb'
 AC_SUBST(xcbincludedir)
 
index 3eacc0d..8c18d71 100644 (file)
@@ -246,13 +246,16 @@ static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port)
 static int _xcb_open_unix(char *protocol, const char *file)
 {
     int fd;
-    struct sockaddr_un addr = { AF_UNIX };
+    struct sockaddr_un addr;
 
     if (protocol && strcmp("unix",protocol))
         return -1;
 
     strcpy(addr.sun_path, file);
-
+    addr.sun_family = AF_UNIX;
+#if HAVE_SOCKADDR_SUN_LEN
+    addr.sun_len = SUN_LEN(&addr);
+#endif
     fd = socket(AF_UNIX, SOCK_STREAM, 0);
     if(fd == -1)
         return -1;