Add a missing pa_xfree.
[pulseaudio.git] / src / tests / ipacl-test.c
blobd1bcb3e3c2679f7ad9102c0375271a91ff3cd134
1 /* $Id$ */
3 #ifdef HAVE_CONFIG_H
4 #include <config.h>
5 #endif
7 #include <sys/types.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <assert.h>
11 #include <string.h>
13 #ifdef HAVE_SYS_SOCKET_H
14 #include <sys/socket.h>
15 #endif
16 #ifdef HAVE_NETINET_IN_H
17 #include <netinet/in.h>
18 #endif
19 #ifdef HAVE_NETINET_IN_SYSTM_H
20 #include <netinet/in_systm.h>
21 #endif
22 #ifdef HAVE_NETINET_IP_H
23 #include <netinet/ip.h>
24 #endif
25 #ifdef HAVE_ARPA_INET_H
26 #include <arpa/inet.h>
27 #endif
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;
36 int fd;
37 int r;
38 pa_ip_acl *acl;
40 fd = socket(PF_INET, SOCK_STREAM, 0);
41 assert(fd >= 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));
48 assert(r >= 0);
50 acl = pa_ip_acl_new("127.0.0.1");
51 assert(acl);
52 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd));
53 pa_ip_acl_free(acl);
55 acl = pa_ip_acl_new("127.0.0.2/0");
56 assert(acl);
57 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd));
58 pa_ip_acl_free(acl);
60 acl = pa_ip_acl_new("127.0.0.1/32");
61 assert(acl);
62 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd));
63 pa_ip_acl_free(acl);
65 acl = pa_ip_acl_new("127.0.0.1/7");
66 assert(acl);
67 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd));
68 pa_ip_acl_free(acl);
70 acl = pa_ip_acl_new("127.0.0.2");
71 assert(acl);
72 printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd));
73 pa_ip_acl_free(acl);
75 acl = pa_ip_acl_new("127.0.0.0/8;0.0.0.0/32");
76 assert(acl);
77 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd));
78 pa_ip_acl_free(acl);
80 acl = pa_ip_acl_new("128.0.0.2/9");
81 assert(acl);
82 printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd));
83 pa_ip_acl_free(acl);
85 acl = pa_ip_acl_new("::1/9");
86 assert(acl);
87 printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd));
88 pa_ip_acl_free(acl);
90 close(fd);
92 fd = socket(PF_INET6, SOCK_STREAM, 0);
93 assert(fd >= 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));
101 assert(r >= 0);
103 acl = pa_ip_acl_new("::1");
104 assert(acl);
105 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd));
106 pa_ip_acl_free(acl);
108 acl = pa_ip_acl_new("::1/9");
109 assert(acl);
110 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd));
111 pa_ip_acl_free(acl);
113 acl = pa_ip_acl_new("::/0");
114 assert(acl);
115 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd));
116 pa_ip_acl_free(acl);
118 acl = pa_ip_acl_new("::2/128");
119 assert(acl);
120 printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd));
121 pa_ip_acl_free(acl);
123 acl = pa_ip_acl_new("::2/127");
124 assert(acl);
125 printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd));
126 pa_ip_acl_free(acl);
128 acl = pa_ip_acl_new("::2/126");
129 assert(acl);
130 printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd));
131 pa_ip_acl_free(acl);
133 close(fd);
135 return 0;