]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bind/tests/test_cidr.c
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / contrib / bind / tests / test_cidr.c
1 #include <sys/types.h>
2 #include <sys/socket.h>
3 #include <netinet/in.h>
4 #include <arpa/inet.h>
5 #include <stdio.h>
6
7 static void test(const char *);
8
9 int
10 main() {
11         test("192.5.4.0/23");
12         test("192.5.4.0");
13         test("192.5.5.1");
14         test("192.5.5.1/23");
15         test("192.5.5.1/24");
16         test("192.5.5.1/28");
17         test("192.5.5.1/32");
18         return (0);
19 }
20
21 static void
22 test(const char *input) {
23         int bits;
24         u_char temp[sizeof (struct in_addr)];
25         char output[sizeof "255.255.255.255/32"];
26
27         memset(temp, 0x5e, sizeof temp);
28         if (inet_cidr_pton(AF_INET, input, temp, &bits) < 0) {
29                 perror(input);
30                 exit(1);
31         }
32         if (inet_cidr_ntop(AF_INET, temp, bits, output, sizeof output)==NULL){
33                 perror("inet_cidr_ntop");
34                 exit(1);
35         }
36         printf("input '%s', temp '%x %x %x %x', bits %d, output '%s'\n",
37                input, temp[0], temp[1], temp[2], temp[3], bits, output);
38 }