]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/ipacl.c
core: add missing SET_PORT_LATENCY_OFFSET to dispatcher opcode string table
[pulseaudio] / src / pulsecore / ipacl.c
index 9b22e8f55b28192e01e7ade1cbe28b2aa9c2aedd..5455d0e876b11d5f7b9a1ed31a05213ac71c16a0 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
@@ -30,9 +28,6 @@
 #include <sys/types.h>
 #include <string.h>
 
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
@@ -42,9 +37,6 @@
 #ifdef HAVE_NETINET_IP_H
 #include <netinet/ip.h>
 #endif
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
 
 #include <pulse/xmalloc.h>
 
 #include <pulsecore/llist.h>
 #include <pulsecore/log.h>
 #include <pulsecore/macro.h>
-#include <pulsecore/winsock.h>
-
-#ifndef HAVE_INET_PTON
-#include "inet_pton.h"
-#endif
+#include <pulsecore/socket.h>
+#include <pulsecore/arpa-inet.h>
 
 #include "ipacl.h"
 
@@ -64,7 +53,9 @@ struct acl_entry {
     PA_LLIST_FIELDS(struct acl_entry);
     int family;
     struct in_addr address_ipv4;
+#ifdef HAVE_IPV6
     struct in6_addr address_ipv6;
+#endif
     int bits;
 };
 
@@ -111,6 +102,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
             if (e.bits < 32 && (uint32_t) (ntohl(e.address_ipv4.s_addr) << e.bits) != 0)
                 pa_log_warn("Host part of ACL entry '%s/%u' is not zero!", a, e.bits);
 
+#ifdef HAVE_IPV6
         } else if (inet_pton(AF_INET6, a, &e.address_ipv6) > 0) {
 
             e.bits = bits == (uint32_t) -1 ? 128 : (int) bits;
@@ -124,7 +116,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
             if (e.bits < 128) {
                 int t = 0, i;
 
-                for (i = 0, bits = e.bits; i < 16; i++) {
+                for (i = 0, bits = (uint32_t) e.bits; i < 16; i++) {
 
                     if (bits >= 8)
                         bits -= 8;
@@ -140,6 +132,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
                 if (t)
                     pa_log_warn("Host part of ACL entry '%s/%u' is not zero!", a, e.bits);
             }
+#endif
 
         } else {
             pa_log_warn("Failed to parse address: %s", a);
@@ -176,7 +169,7 @@ void pa_ip_acl_free(pa_ip_acl *acl) {
 int pa_ip_acl_check(pa_ip_acl *acl, int fd) {
     struct sockaddr_storage sa;
     struct acl_entry *e;
-    socklen_t  salen;
+    socklen_t salen;
 
     pa_assert(acl);
     pa_assert(fd >= 0);
@@ -185,14 +178,20 @@ int pa_ip_acl_check(pa_ip_acl *acl, int fd) {
     if (getpeername(fd, (struct sockaddr*) &sa, &salen) < 0)
         return -1;
 
+#ifdef HAVE_IPV6
     if (sa.ss_family != AF_INET && sa.ss_family != AF_INET6)
+#else
+    if (sa.ss_family != AF_INET)
+#endif
         return -1;
 
     if (sa.ss_family == AF_INET && salen != sizeof(struct sockaddr_in))
         return -1;
 
+#ifdef HAVE_IPV6
     if (sa.ss_family == AF_INET6 && salen != sizeof(struct sockaddr_in6))
         return -1;
+#endif
 
     for (e = acl->entries; e; e = e->next) {
 
@@ -205,8 +204,9 @@ int pa_ip_acl_check(pa_ip_acl *acl, int fd) {
             if (e->bits == 0 || /* this needs special handling because >> takes the right-hand side modulo 32 */
                 (ntohl(sai->sin_addr.s_addr ^ e->address_ipv4.s_addr) >> (32 - e->bits)) == 0)
                 return 1;
+#ifdef HAVE_IPV6
         } else if (e->family == AF_INET6) {
-            int i, bits ;
+            int i, bits;
             struct sockaddr_in6 *sai = (struct sockaddr_in6*) &sa;
 
             if (e->bits == 128)
@@ -232,6 +232,7 @@ int pa_ip_acl_check(pa_ip_acl *acl, int fd) {
                 if (bits == 0)
                     return 1;
             }
+#endif
         }
     }