printhash.c revision 288683
1/* $FreeBSD: head/contrib/ipfilter/lib/printhash.c 255332 2013-09-06 23:11:19Z cy $ */ 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 12iphtable_t * 13printhash(hp, copyfunc, name, opts, fields) 14 iphtable_t *hp; 15 copyfunc_t copyfunc; 16 char *name; 17 int opts; 18 wordtab_t *fields; 19{ 20 iphtent_t *ipep, **table; 21 iphtable_t iph; 22 int printed; 23 size_t sz; 24 25 if ((*copyfunc)((char *)hp, (char *)&iph, sizeof(iph))) 26 return NULL; 27 28 if ((name != NULL) && strncmp(name, iph.iph_name, FR_GROUPLEN)) 29 return iph.iph_next; 30 31 if (fields == NULL) 32 printhashdata(hp, opts); 33 34 if ((hp->iph_flags & IPHASH_DELETE) != 0) 35 PRINTF("# "); 36 37 if ((opts & OPT_DEBUG) == 0) 38 PRINTF("\t{"); 39 40 sz = iph.iph_size * sizeof(*table); 41 table = malloc(sz); 42 if ((*copyfunc)((char *)iph.iph_table, (char *)table, sz)) 43 return NULL; 44 45 for (printed = 0, ipep = iph.iph_list; ipep != NULL; ) { 46 ipep = printhashnode(&iph, ipep, copyfunc, opts, fields); 47 printed++; 48 } 49 if (printed == 0) 50 putchar(';'); 51 52 free(table); 53 54 if ((opts & OPT_DEBUG) == 0) 55 PRINTF(" };\n"); 56 57 return iph.iph_next; 58} 59