10 #ifdef HAVE_NETINET_IN_H
11 #include <netinet/in.h>
13 #ifdef HAVE_NETINET_IN_SYSTM_H
14 #include <netinet/in_systm.h>
16 #ifdef HAVE_NETINET_IP_H
17 #include <netinet/ip.h>
20 #include <pulsecore/log.h>
21 #include <pulsecore/macro.h>
22 #include <pulsecore/socket.h>
23 #include <pulsecore/ipacl.h>
24 #include <pulsecore/arpa-inet.h>
26 static void do_ip_acl_check(const char *s, int fd, int expected) {
30 pa_assert_se(acl = pa_ip_acl_new(s));
31 result = pa_ip_acl_check(acl, fd);
34 pa_log_info("%-20s result=%u (should be %u)", s, result, expected);
35 pa_assert(result == expected);
38 int main(int argc, char *argv[]) {
39 struct sockaddr_in sa;
41 struct sockaddr_in6 sa6;
46 if (!getenv("MAKE_CHECK"))
47 pa_log_set_level(PA_LOG_DEBUG);
49 fd = socket(PF_INET, SOCK_STREAM, 0);
52 sa.sin_family = AF_INET;
53 sa.sin_port = htons(22);
54 sa.sin_addr.s_addr = inet_addr("127.0.0.1");
56 r = connect(fd, (struct sockaddr*) &sa, sizeof(sa));
59 do_ip_acl_check("127.0.0.1", fd, 1);
60 do_ip_acl_check("127.0.0.2/0", fd, 1);
61 do_ip_acl_check("127.0.0.1/32", fd, 1);
62 do_ip_acl_check("127.0.0.1/7", fd, 1);
63 do_ip_acl_check("127.0.0.2", fd, 0);
64 do_ip_acl_check("127.0.0.0/8;0.0.0.0/32", fd, 1);
65 do_ip_acl_check("128.0.0.2/9", fd, 0);
66 do_ip_acl_check("::1/9", fd, 0);
71 if ( (fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0 ) {
72 pa_log_error("Unable to open IPv6 socket, IPv6 tests ignored");
76 memset(&sa6, 0, sizeof(sa6));
77 sa6.sin6_family = AF_INET6;
78 sa6.sin6_port = htons(22);
79 pa_assert_se(inet_pton(AF_INET6, "::1", &sa6.sin6_addr) == 1);
81 r = connect(fd, (struct sockaddr*) &sa6, sizeof(sa6));
84 do_ip_acl_check("::1", fd, 1);
85 do_ip_acl_check("::1/9", fd, 1);
86 do_ip_acl_check("::/0", fd, 1);
87 do_ip_acl_check("::2/128", fd, 0);
88 do_ip_acl_check("::2/127", fd, 0);
89 do_ip_acl_check("::2/126", fd, 1);