1 /*        $NetBSD: printdstlist.c,v 1.1.1.2 2012/07/22 13:44:40 darrenr Exp $   */
2 
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  */
8 
9 #include "ipf.h"
10 
11 
12 ippool_dst_t *
printdstlist(pp,copyfunc,name,opts,nodes,fields)13 printdstlist(pp, copyfunc, name, opts, nodes, fields)
14           ippool_dst_t *pp;
15           copyfunc_t copyfunc;
16           char *name;
17           int opts;
18           ipf_dstnode_t *nodes;
19           wordtab_t *fields;
20 {
21           ipf_dstnode_t *node;
22           ippool_dst_t dst;
23 
24           if ((*copyfunc)(pp, &dst, sizeof(dst)))
25                     return NULL;
26 
27           if ((name != NULL) && strncmp(name, dst.ipld_name, FR_GROUPLEN))
28                     return dst.ipld_next;
29 
30           if (fields == NULL)
31                     printdstlistdata(&dst, opts);
32 
33           if ((dst.ipld_flags & IPDST_DELETE) != 0)
34                     PRINTF("# ");
35           if ((opts & OPT_DEBUG) == 0)
36                     PRINTF("\t{");
37 
38           if (nodes == NULL) {
39                     putchar(';');
40           } else {
41                     for (node = nodes; node != NULL; ) {
42                               ipf_dstnode_t *n;
43 
44                               n = calloc(1, node->ipfd_size);
45                               if (n == NULL)
46                                         break;
47                               if ((*copyfunc)(node, n, node->ipfd_size)) {
48                                         free(n);
49                                         return NULL;
50                               }
51 
52                               node = printdstlistnode(n, bcopywrap, opts, fields);
53 
54                               free(n);
55                     }
56           }
57 
58           if ((opts & OPT_DEBUG) == 0)
59                     PRINTF(" };\n");
60 
61           return dst.ipld_next;
62 }
63