printpool.c revision 170268
1226031Sstas/* $FreeBSD: head/contrib/ipfilter/lib/printpool.c 170268 2007-06-04 02:54:36Z darrenr $ */ 2226031Sstas 3226031Sstas/* 4226031Sstas * Copyright (C) 2002-2005 by Darren Reed. 5226031Sstas * 6226031Sstas * See the IPFILTER.LICENCE file for details on licencing. 7226031Sstas */ 8226031Sstas 9226031Sstas#include "ipf.h" 10226031Sstas 11226031Sstas#define PRINTF (void)printf 12226031Sstas#define FPRINTF (void)fprintf 13226031Sstas 14226031Sstasip_pool_t *printpool(pp, copyfunc, name, opts) 15226031Sstasip_pool_t *pp; 16226031Sstascopyfunc_t copyfunc; 17226031Sstaschar *name; 18226031Sstasint opts; 19226031Sstas{ 20226031Sstas ip_pool_node_t *ipnp, *ipnpn, ipn; 21226031Sstas ip_pool_t ipp; 22226031Sstas 23226031Sstas if ((*copyfunc)(pp, &ipp, sizeof(ipp))) 24226031Sstas return NULL; 25226031Sstas 26226031Sstas if ((name != NULL) && strncmp(name, ipp.ipo_name, FR_GROUPLEN)) 27226031Sstas return ipp.ipo_next; 28226031Sstas 29226031Sstas printpooldata(&ipp, opts); 30226031Sstas 31226031Sstas if ((ipp.ipo_flags & IPOOL_DELETE) != 0) 32226031Sstas PRINTF("# "); 33226031Sstas if ((opts & OPT_DEBUG) == 0) 34226031Sstas PRINTF("\t{"); 35226031Sstas 36226031Sstas ipnpn = ipp.ipo_list; 37226031Sstas ipp.ipo_list = NULL; 38226031Sstas while (ipnpn != NULL) { 39226031Sstas ipnp = (ip_pool_node_t *)malloc(sizeof(*ipnp)); 40226031Sstas (*copyfunc)(ipnpn, ipnp, sizeof(ipn)); 41226031Sstas ipnpn = ipnp->ipn_next; 42226031Sstas ipnp->ipn_next = ipp.ipo_list; 43226031Sstas ipp.ipo_list = ipnp; 44226031Sstas } 45226031Sstas 46226031Sstas if (ipp.ipo_list == NULL) { 47226031Sstas putchar(';'); 48226031Sstas } else { 49226031Sstas for (ipnp = ipp.ipo_list; ipnp != NULL; ) { 50226031Sstas ipnp = printpoolnode(ipnp, opts); 51226031Sstas 52226031Sstas if ((opts & OPT_DEBUG) == 0) { 53226031Sstas putchar(';'); 54226031Sstas } 55226031Sstas } 56226031Sstas } 57226031Sstas 58226031Sstas if ((opts & OPT_DEBUG) == 0) 59226031Sstas PRINTF(" };\n"); 60226031Sstas 61226031Sstas return ipp.ipo_next; 62226031Sstas} 63226031Sstas