summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/lib/printdstlist.c
blob: 829a1d2e69ced5dc99cf7d43177e81d5f94b881d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * Copyright (C) 2012 by Darren Reed.
 *
 * See the IPFILTER.LICENCE file for details on licencing.
 */

#include "ipf.h"


ippool_dst_t *
printdstlist(pp, copyfunc, name, opts, nodes, fields)
	ippool_dst_t *pp;
	copyfunc_t copyfunc;
	char *name;
	int opts;
	ipf_dstnode_t *nodes;
	wordtab_t *fields;
{
	ipf_dstnode_t *node;
	ippool_dst_t dst;

	if ((*copyfunc)(pp, &dst, sizeof(dst)))
		return NULL;

	if ((name != NULL) && strncmp(name, dst.ipld_name, FR_GROUPLEN))
		return dst.ipld_next;

	if (fields == NULL)
		printdstlistdata(&dst, opts);

	if ((dst.ipld_flags & IPDST_DELETE) != 0)
		PRINTF("# ");
	if ((opts & OPT_DEBUG) == 0)
		PRINTF("\t{");

	if (nodes == NULL) {
		putchar(';');
	} else {
		for (node = nodes; node != NULL; ) {
			ipf_dstnode_t *n;

			n = calloc(1, node->ipfd_size);
			if (n == NULL)
				break;
			if ((*copyfunc)(node, n, node->ipfd_size)) {
				free(n);
				return NULL;
			}

			node = printdstlistnode(n, bcopywrap, opts, fields);

			free(n);
		}
	}

	if ((opts & OPT_DEBUG) == 0)
		PRINTF(" };\n");

	return dst.ipld_next;
}
OpenPOWER on IntegriCloud