1254219Scy/*
2254219Scy * Copyright (C) 2012 by Darren Reed.
3254219Scy *
4254219Scy * See the IPFILTER.LICENCE file for details on licencing.
5254219Scy */
6254219Scy
7254219Scy#include "ipf.h"
8254219Scy
9254219Scy
10254219Scyippool_dst_t *
11254219Scyprintdstlist(pp, copyfunc, name, opts, nodes, fields)
12254219Scy	ippool_dst_t *pp;
13254219Scy	copyfunc_t copyfunc;
14254219Scy	char *name;
15254219Scy	int opts;
16254219Scy	ipf_dstnode_t *nodes;
17254219Scy	wordtab_t *fields;
18254219Scy{
19254219Scy	ipf_dstnode_t *node;
20254219Scy	ippool_dst_t dst;
21254219Scy
22254219Scy	if ((*copyfunc)(pp, &dst, sizeof(dst)))
23254219Scy		return NULL;
24254219Scy
25254219Scy	if ((name != NULL) && strncmp(name, dst.ipld_name, FR_GROUPLEN))
26254219Scy		return dst.ipld_next;
27254219Scy
28254219Scy	if (fields == NULL)
29254219Scy		printdstlistdata(&dst, opts);
30254219Scy
31254219Scy	if ((dst.ipld_flags & IPDST_DELETE) != 0)
32254219Scy		PRINTF("# ");
33254219Scy	if ((opts & OPT_DEBUG) == 0)
34254219Scy		PRINTF("\t{");
35254219Scy
36254219Scy	if (nodes == NULL) {
37254219Scy		putchar(';');
38254219Scy	} else {
39254219Scy		for (node = nodes; node != NULL; ) {
40254219Scy			ipf_dstnode_t *n;
41254219Scy
42254219Scy			n = calloc(1, node->ipfd_size);
43254219Scy			if (n == NULL)
44254219Scy				break;
45254219Scy			if ((*copyfunc)(node, n, node->ipfd_size)) {
46254219Scy				free(n);
47254219Scy				return NULL;
48254219Scy			}
49254219Scy
50254219Scy			node = printdstlistnode(n, bcopywrap, opts, fields);
51254219Scy
52254219Scy			free(n);
53254219Scy		}
54254219Scy	}
55254219Scy
56254219Scy	if ((opts & OPT_DEBUG) == 0)
57254219Scy		PRINTF(" };\n");
58254219Scy
59254219Scy	return dst.ipld_next;
60254219Scy}
61