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