xref: /netbsd-src/external/bsd/ipf/dist/lib/printpool.c (revision b757af438b42b93f8c6571f026d8b8ef3eaf5fc9)
1 /*	$NetBSD: printpool.c,v 1.1.1.1 2012/03/23 21:20:10 christos 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 ip_pool_t *
13 printpool(pp, copyfunc, name, opts, fields)
14 	ip_pool_t *pp;
15 	copyfunc_t copyfunc;
16 	char *name;
17 	int opts;
18 	wordtab_t *fields;
19 {
20 	ip_pool_node_t *ipnp, *ipnpn, ipn;
21 	ip_pool_t ipp;
22 
23 	if ((*copyfunc)(pp, &ipp, sizeof(ipp)))
24 		return NULL;
25 
26 	if ((name != NULL) && strncmp(name, ipp.ipo_name, FR_GROUPLEN))
27 		return ipp.ipo_next;
28 
29 	printpooldata(&ipp, opts);
30 
31 	if ((ipp.ipo_flags & IPOOL_DELETE) != 0)
32 		PRINTF("# ");
33 	if ((opts & OPT_DEBUG) == 0)
34 		PRINTF("\t{");
35 
36 	ipnpn = ipp.ipo_list;
37 	ipp.ipo_list = NULL;
38 	while (ipnpn != NULL) {
39 		ipnp = (ip_pool_node_t *)malloc(sizeof(*ipnp));
40 		(*copyfunc)(ipnpn, ipnp, sizeof(ipn));
41 		ipnpn = ipnp->ipn_next;
42 		ipnp->ipn_next = ipp.ipo_list;
43 		ipp.ipo_list = ipnp;
44 	}
45 
46 	if (ipp.ipo_list == NULL) {
47 		putchar(';');
48 	} else {
49 		for (ipnp = ipp.ipo_list; ipnp != NULL; ipnp = ipnpn) {
50 			ipnpn = printpoolnode(ipnp, opts, fields);
51 			free(ipnp);
52 
53 			if ((opts & OPT_DEBUG) == 0) {
54 				putchar(';');
55 			}
56 		}
57 	}
58 
59 	if ((opts & OPT_DEBUG) == 0)
60 		PRINTF(" };\n");
61 
62 	return ipp.ipo_next;
63 }
64