]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ipfilter/lib/printpool.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ipfilter / lib / printpool.c
1 /*      $FreeBSD$       */
2
3 /*
4  * Copyright (C) 2002-2005 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  */
8
9 #include "ipf.h"
10
11 #define PRINTF  (void)printf
12 #define FPRINTF (void)fprintf
13
14 ip_pool_t *printpool(pp, copyfunc, name, opts)
15 ip_pool_t *pp;
16 copyfunc_t copyfunc;
17 char *name;
18 int opts;
19 {
20         ip_pool_node_t *ipnp, *ipnpn, ipn;
21         ip_pool_t ipp;
22
23         if ((*copyfunc)(pp, &ipp, sizeof(ipp)))
24                 return NULL;
25
26         if ((name != NULL) && strncmp(name, ipp.ipo_name, FR_GROUPLEN))
27                 return ipp.ipo_next;
28
29         printpooldata(&ipp, opts);
30
31         if ((ipp.ipo_flags & IPOOL_DELETE) != 0)
32                 PRINTF("# ");
33         if ((opts & OPT_DEBUG) == 0)
34                 PRINTF("\t{");
35
36         ipnpn = ipp.ipo_list;
37         ipp.ipo_list = NULL;
38         while (ipnpn != NULL) {
39                 ipnp = (ip_pool_node_t *)malloc(sizeof(*ipnp));
40                 (*copyfunc)(ipnpn, ipnp, sizeof(ipn));
41                 ipnpn = ipnp->ipn_next;
42                 ipnp->ipn_next = ipp.ipo_list;
43                 ipp.ipo_list = ipnp;
44         }
45
46         if (ipp.ipo_list == NULL) {
47                 putchar(';');
48         } else {
49                 for (ipnp = ipp.ipo_list; ipnp != NULL; ) {
50                         ipnp = printpoolnode(ipnp, opts);
51
52                         if ((opts & OPT_DEBUG) == 0) {
53                                 putchar(';');
54                         }
55                 }
56         }
57
58         if ((opts & OPT_DEBUG) == 0)
59                 PRINTF(" };\n");
60
61         return ipp.ipo_next;
62 }