printhash.c revision 255332
1274075Sngie/*	$FreeBSD: head/contrib/ipfilter/lib/printhash.c 255332 2013-09-06 23:11:19Z cy $	*/
2274075Sngie
3274075Sngie/*
4274075Sngie * Copyright (C) 2012 by Darren Reed.
5274075Sngie *
6274075Sngie * See the IPFILTER.LICENCE file for details on licencing.
7274075Sngie */
8274075Sngie
9274075Sngie#include "ipf.h"
10274075Sngie
11274075Sngie
12274075Sngieiphtable_t *
13274075Sngieprinthash(hp, copyfunc, name, opts, fields)
14274075Sngie	iphtable_t *hp;
15274075Sngie	copyfunc_t copyfunc;
16274075Sngie	char *name;
17274075Sngie	int opts;
18274075Sngie	wordtab_t *fields;
19274075Sngie{
20274075Sngie	iphtent_t *ipep, **table;
21274075Sngie	iphtable_t iph;
22274075Sngie	int printed;
23274075Sngie	size_t sz;
24274075Sngie
25274075Sngie	if ((*copyfunc)((char *)hp, (char *)&iph, sizeof(iph)))
26274075Sngie		return NULL;
27274075Sngie
28274075Sngie	if ((name != NULL) && strncmp(name, iph.iph_name, FR_GROUPLEN))
29274075Sngie		return iph.iph_next;
30274075Sngie
31274075Sngie	if (fields == NULL)
32274075Sngie		printhashdata(hp, opts);
33274075Sngie
34274075Sngie	if ((hp->iph_flags & IPHASH_DELETE) != 0)
35274075Sngie		PRINTF("# ");
36274075Sngie
37274075Sngie	if ((opts & OPT_DEBUG) == 0)
38274075Sngie		PRINTF("\t{");
39274075Sngie
40274075Sngie	sz = iph.iph_size * sizeof(*table);
41274075Sngie	table = malloc(sz);
42274075Sngie	if ((*copyfunc)((char *)iph.iph_table, (char *)table, sz))
43274075Sngie		return NULL;
44274075Sngie
45274075Sngie	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