]> git.sesse.net Git - vlc/blobdiff - src/network/rootbind.c
Merge branch 'master' of git://git.videolan.org/vlc
[vlc] / src / network / rootbind.c
index c6546d4c421335a9afd71d3664c2550ef171a402..65a956fbaf1d75a207e975b3176ec7a89b15e663 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
 
+#define _XPG4_2 /* ancilliary data on Solaris */
+
 #if !defined (WIN32) && !defined (SYS_BEOS)
 # define ENABLE_ROOTWRAP 1
 #endif
@@ -35,6 +37,7 @@ int rootwrap_bind (int, int, int, const struct sockaddr *, size_t);
 #ifdef ENABLE_ROOTWRAP
 
 #include <string.h>
+#include <stdlib.h>
 
 #include <sys/types.h>
 #include <unistd.h>
@@ -44,6 +47,17 @@ int rootwrap_bind (int, int, int, const struct sockaddr *, size_t);
 #include <netinet/in.h>
 #include <pthread.h>
 
+/* Required yet non-standard cmsg functions */
+#ifndef CMSG_ALIGN
+# define CMSG_ALIGN(len) (((len) + sizeof(intptr_t)-1) & ~(sizeof(intptr_t)-1))
+#endif
+#ifndef CMSG_SPACE
+# define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
+#endif
+#ifndef CMSG_LEN
+# define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
+#endif
+
 /**
  * Receive a file descriptor from another process
  */
@@ -97,7 +111,7 @@ int rootwrap_bind (int family, int socktype, int protocol,
 
     const char *sockenv = getenv ("VLC_ROOTWRAP_SOCK");
     if (sockenv != NULL)
-        sock = atoi (sock);
+        sock = atoi (sockenv);
     if (sock == -1)
     {
         errno = EACCES;
@@ -144,7 +158,7 @@ int rootwrap_bind (int family, int socktype, int protocol,
     }
 
     memset (&ss, 0, sizeof (ss));
-    memcpy (&ss, addr, alen > sizeof (ss) ? sizeof (ss) : alen);
+    memcpy (&ss, addr, (alen > sizeof (ss)) ? sizeof (ss) : alen);
 
     pthread_mutex_lock (&mutex);
     if (send (sock, &ss, sizeof (ss), 0) != sizeof (ss))