Home | History | Annotate | Line # | Download | only in lib
printhash.c revision 1.1
      1  1.1  christos /*	$NetBSD: printhash.c,v 1.1 2012/03/23 21:20:09 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (C) 2010 by Darren Reed.
      5  1.1  christos  *
      6  1.1  christos  * See the IPFILTER.LICENCE file for details on licencing.
      7  1.1  christos  */
      8  1.1  christos 
      9  1.1  christos #include "ipf.h"
     10  1.1  christos 
     11  1.1  christos 
     12  1.1  christos iphtable_t *
     13  1.1  christos printhash(hp, copyfunc, name, opts, fields)
     14  1.1  christos 	iphtable_t *hp;
     15  1.1  christos 	copyfunc_t copyfunc;
     16  1.1  christos 	char *name;
     17  1.1  christos 	int opts;
     18  1.1  christos 	wordtab_t *fields;
     19  1.1  christos {
     20  1.1  christos 	iphtent_t *ipep, **table;
     21  1.1  christos 	iphtable_t iph;
     22  1.1  christos 	int printed;
     23  1.1  christos 	size_t sz;
     24  1.1  christos 
     25  1.1  christos 	if ((*copyfunc)((char *)hp, (char *)&iph, sizeof(iph)))
     26  1.1  christos 		return NULL;
     27  1.1  christos 
     28  1.1  christos 	if ((name != NULL) && strncmp(name, iph.iph_name, FR_GROUPLEN))
     29  1.1  christos 		return iph.iph_next;
     30  1.1  christos 
     31  1.1  christos 	if (fields == NULL)
     32  1.1  christos 		printhashdata(hp, opts);
     33  1.1  christos 
     34  1.1  christos 	if ((hp->iph_flags & IPHASH_DELETE) != 0)
     35  1.1  christos 		PRINTF("# ");
     36  1.1  christos 
     37  1.1  christos 	if ((opts & OPT_DEBUG) == 0)
     38  1.1  christos 		PRINTF("\t{");
     39  1.1  christos 
     40  1.1  christos 	sz = iph.iph_size * sizeof(*table);
     41  1.1  christos 	table = malloc(sz);
     42  1.1  christos 	if ((*copyfunc)((char *)iph.iph_table, (char *)table, sz))
     43  1.1  christos 		return NULL;
     44  1.1  christos 
     45  1.1  christos 	for (printed = 0, ipep = iph.iph_list; ipep != NULL; ) {
     46  1.1  christos 		ipep = printhashnode(&iph, ipep, copyfunc, opts, fields);
     47  1.1  christos 		printed++;
     48  1.1  christos 	}
     49  1.1  christos 	if (printed == 0)
     50  1.1  christos 		putchar(';');
     51  1.1  christos 
     52  1.1  christos 	free(table);
     53  1.1  christos 
     54  1.1  christos 	if ((opts & OPT_DEBUG) == 0)
     55  1.1  christos 		PRINTF(" };\n");
     56  1.1  christos 
     57  1.1  christos 	return iph.iph_next;
     58  1.1  christos }
     59