13 #ifdef HAVE_SYS_SOCKET_H
14 #include <sys/socket.h>
16 #ifdef HAVE_NETINET_IN_H
17 #include <netinet/in.h>
19 #ifdef HAVE_NETINET_IN_SYSTM_H
20 #include <netinet/in_systm.h>
22 #ifdef HAVE_NETINET_IP_H
23 #include <netinet/ip.h>
25 #ifdef HAVE_ARPA_INET_H
26 #include <arpa/inet.h>
29 #include "../pulsecore/winsock.h"
31 #include <pulsecore/ipacl.h>
33 int main(int argc
, char *argv
[]) {
34 struct sockaddr_in sa
;
35 struct sockaddr_in6 sa6
;
40 fd
= socket(PF_INET
, SOCK_STREAM
, 0);
43 sa
.sin_family
= AF_INET
;
44 sa
.sin_port
= htons(22);
45 sa
.sin_addr
.s_addr
= inet_addr("127.0.0.1");
47 r
= connect(fd
, (struct sockaddr
*) &sa
, sizeof(sa
));
50 acl
= pa_ip_acl_new("127.0.0.1");
52 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl
, fd
));
55 acl
= pa_ip_acl_new("127.0.0.2/0");
57 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl
, fd
));
60 acl
= pa_ip_acl_new("127.0.0.1/32");
62 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl
, fd
));
65 acl
= pa_ip_acl_new("127.0.0.1/7");
67 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl
, fd
));
70 acl
= pa_ip_acl_new("127.0.0.2");
72 printf("result=%u (should be 0)\n", pa_ip_acl_check(acl
, fd
));
75 acl
= pa_ip_acl_new("127.0.0.0/8;0.0.0.0/32");
77 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl
, fd
));
80 acl
= pa_ip_acl_new("128.0.0.2/9");
82 printf("result=%u (should be 0)\n", pa_ip_acl_check(acl
, fd
));
85 acl
= pa_ip_acl_new("::1/9");
87 printf("result=%u (should be 0)\n", pa_ip_acl_check(acl
, fd
));
92 fd
= socket(PF_INET6
, SOCK_STREAM
, 0);
95 memset(&sa6
, 0, sizeof(sa6
));
96 sa6
.sin6_family
= AF_INET6
;
97 sa6
.sin6_port
= htons(22);
98 inet_pton(AF_INET6
, "::1", &sa6
.sin6_addr
);
100 r
= connect(fd
, (struct sockaddr
*) &sa6
, sizeof(sa6
));
103 acl
= pa_ip_acl_new("::1");
105 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl
, fd
));
108 acl
= pa_ip_acl_new("::1/9");
110 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl
, fd
));
113 acl
= pa_ip_acl_new("::/0");
115 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl
, fd
));
118 acl
= pa_ip_acl_new("::2/128");
120 printf("result=%u (should be 0)\n", pa_ip_acl_check(acl
, fd
));
123 acl
= pa_ip_acl_new("::2/127");
125 printf("result=%u (should be 0)\n", pa_ip_acl_check(acl
, fd
));
128 acl
= pa_ip_acl_new("::2/126");
130 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl
, fd
));