summaryrefslogtreecommitdiffstats
path: root/src/tests/ipacl-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/ipacl-test.c')
-rw-r--r--src/tests/ipacl-test.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/src/tests/ipacl-test.c b/src/tests/ipacl-test.c
index b98151ee..be9caadf 100644
--- a/src/tests/ipacl-test.c
+++ b/src/tests/ipacl-test.c
@@ -1,30 +1,44 @@
-/* $Id$ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
+#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
-#include <arpa/inet.h>
#include <assert.h>
#include <string.h>
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NETINET_IN_SYSTM_H
+#include <netinet/in_systm.h>
+#endif
+#ifdef HAVE_NETINET_IP_H
+#include <netinet/ip.h>
+#endif
+
+#include <pulsecore/socket.h>
+#include <pulsecore/macro.h>
#include <pulsecore/ipacl.h>
+#include <pulsecore/arpa-inet.h>
int main(int argc, char *argv[]) {
struct sockaddr_in sa;
+#ifdef HAVE_IPV6
struct sockaddr_in6 sa6;
+#endif
int fd;
int r;
pa_ip_acl *acl;
- fd = socket(PF_INET, SOCK_STREAM, 0);
+ fd = socket(PF_INET, SOCK_STREAM, 0);
assert(fd >= 0);
-
+
sa.sin_family = AF_INET;
sa.sin_port = htons(22);
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
-
+
r = connect(fd, (struct sockaddr*) &sa, sizeof(sa));
assert(r >= 0);
@@ -47,7 +61,7 @@ int main(int argc, char *argv[]) {
assert(acl);
printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd));
pa_ip_acl_free(acl);
-
+
acl = pa_ip_acl_new("127.0.0.2");
assert(acl);
printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd));
@@ -67,17 +81,20 @@ int main(int argc, char *argv[]) {
assert(acl);
printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd));
pa_ip_acl_free(acl);
-
+
close(fd);
- fd = socket(PF_INET6, SOCK_STREAM, 0);
- assert(fd >= 0);
+#ifdef HAVE_IPV6
+ if ( (fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0 ) {
+ printf("Unable to open IPv6 socket, IPv6 tests ignored");
+ return 0;
+ }
memset(&sa6, 0, sizeof(sa6));
sa6.sin6_family = AF_INET6;
sa6.sin6_port = htons(22);
- inet_pton(AF_INET6, "::1", &sa6.sin6_addr);
-
+ pa_assert_se(inet_pton(AF_INET6, "::1", &sa6.sin6_addr) == 1);
+
r = connect(fd, (struct sockaddr*) &sa6, sizeof(sa6));
assert(r >= 0);
@@ -112,6 +129,7 @@ int main(int argc, char *argv[]) {
pa_ip_acl_free(acl);
close(fd);
-
+#endif
+
return 0;
}