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