Home | History | Annotate | Line # | Download | only in lib
      1 /*	$NetBSD: printpool.c,v 1.1.1.2 2012/07/22 13:44:42 darrenr 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, **pnext;
     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 	pnext = &ipp.ipo_list;
     39 	while (ipnpn != NULL) {
     40 		ipnp = (ip_pool_node_t *)malloc(sizeof(*ipnp));
     41 		(*copyfunc)(ipnpn, ipnp, sizeof(ipn));
     42 		ipnpn = ipnp->ipn_next;
     43 		*pnext = ipnp;
     44 		pnext = &ipnp->ipn_next;
     45 		ipnp->ipn_next = NULL;
     46 	}
     47 
     48 	if (ipp.ipo_list == NULL) {
     49 		putchar(';');
     50 	} else {
     51 		for (ipnp = ipp.ipo_list; ipnp != NULL; ipnp = ipnpn) {
     52 			ipnpn = printpoolnode(ipnp, opts, fields);
     53 			free(ipnp);
     54 
     55 			if ((opts & OPT_DEBUG) == 0) {
     56 				putchar(';');
     57 			}
     58 		}
     59 	}
     60 
     61 	if ((opts & OPT_DEBUG) == 0)
     62 		PRINTF(" };\n");
     63 
     64 	return ipp.ipo_next;
     65 }
     66