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