ze-filter  (ze-filter-0.8.0-develop-180218)
ze-ipv6-test.c
Go to the documentation of this file.
1 
2 /*
3  *
4  * ze-filter - Mail Server Filter for sendmail
5  *
6  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
7  *
8  * Auteur : Jose Marcio Martins da Cruz
9  * jose.marcio.mc@gmail.org
10  *
11  * Historique :
12  * Creation : janvier 2002
13  *
14  * This program is free software, but with restricted license :
15  *
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  * More details about ze-filter license can be found at ze-filter
22  * web site : http://foss.jose-marcio.org
23  */
24 
25 #include <ze-sys.h>
26 #include <ze-filter.h>
27 
28 int v6net_hi = 64;
29 int v6net_lo = 32;
30 int v6net_step = 4;
31 
32 void
34 {
35  char *env;
36 
37  env = getenv("IPV6NET");
38  if (env != NULL) {
39  int argc;
40  char *argv[8];
41 
42  argc = zeStr2Tokens(env, 8, argv, ",");
43  if (argc >= 3) {
44  v6net_lo = atoi(argv[0]);
45  v6net_hi = atoi(argv[1]);
46  v6net_step = atoi(argv[2]);
47  }
48  }
49 }
50 
51 int
52 main(argc, argv)
53  int argc;
54  char **argv;
55 {
56  int res = 0;
57  extern int ze_logLevel;
58 
59  bool r;
60 
61  ipv6_T ipv6, ip;
62  char buf[64];
63 
64  char *s = NULL;
65 
66  configure("ze-module-test", conf_file, FALSE);
67 
69  ze_logLevel = 10;
70 
72 
73  printf("Hello, world\n");
74 
75  ipv6_str2rec(&ipv6, "1:2:3:4:5:6:7:8:9:10:11:12:13:14:15");
76  ipv6_str2rec(&ipv6, "2001:0DB8:0:CD30:123:4567:89AB:CDEF");
77  ipv6_str2rec(&ipv6, "2001:0DB8:0:CD30::4567:89AB:CDEF");
78  ipv6_str2rec(&ipv6, "::1");
79  ipv6_str2rec(&ipv6, "::");
80 
81  ipv6_expand(buf, "::1", sizeof (buf));
82  ipv6_expand(buf, "2001:0DB8:0:CD30::4567:89AB:CDEF", sizeof (buf));
83 
84  s = "2001:660:3312::1::2/64";
85  printf(" * IN %s\n", s);
86  if (ipv6_str2rec(&ipv6, s)) {
87  ipv6_rec2str(buf, &ipv6, sizeof (buf));
88  printf(" * PARSED %s\n", buf);
89  }
90 
91  s = "2001:660:33122::1/64";
92  printf(" * IN %s\n", s);
93  if (ipv6_str2rec(&ipv6, s)) {
94  ipv6_rec2str(buf, &ipv6, sizeof (buf));
95  printf(" * PARSED %s\n", buf);
96  }
97 
98  s = "2001:660:3312:ffff::1/64";
99  printf(" * IN %s\n", s);
100  if (ipv6_str2rec(&ipv6, s)) {
101  int i;
102 
103  ipv6_rec2str(buf, &ipv6, sizeof (buf));
104  printf(" * PARSED %s\n", buf);
105 
106  for (i = v6net_hi; i >= v6net_lo; i -= v6net_step) {
107  ipv6_prefix_str(&ipv6, buf, sizeof (buf), i);
108 
109  printf(" * NET %s\n", buf);
110  }
111  }
112  return 0;
113 }
Definition: ze-ipv6.h:32
int ze_logLevel
Definition: zeSyslog.c:34
void zeLog_SetOutput(bool, bool)
Definition: zeSyslog.c:490
#define FALSE
Definition: macros.h:160
int main(int argc, char **argv)
Definition: ze-ipv6-test.c:52
int zeStr2Tokens(char *, int, char **, char *)
Definition: zeStrings.c:610
bool ipv6_str2rec(ipv6_T *ipv6, char *sin)
Definition: ze-ipv6.c:96
void ipv6_expand(char *sout, char *sin, size_t size)
Definition: ze-ipv6.c:68
int v6net_step
Definition: ze-ipv6-test.c:30
void ipv6_init_nets()
Definition: ze-ipv6-test.c:33
#define TRUE
Definition: macros.h:157
char * conf_file
Definition: ze-cf.c:38
int configure(char *, char *, bool)
Definition: ze-cf.c:1203
int v6net_hi
Definition: ze-ipv6-test.c:28
int v6net_lo
Definition: ze-ipv6-test.c:29
void ipv6_prefix_str(ipv6_T *addr, char *buf, size_t size, int n)
Definition: ze-ipv6.c:290
void ipv6_rec2str(char *sout, ipv6_T *ipv6, size_t sz)
Definition: ze-ipv6.c:210