printhash.c revision 170268
1/*	$FreeBSD: head/contrib/ipfilter/lib/printhash.c 170268 2007-06-04 02:54:36Z darrenr $	*/
2
3/*
4 * Copyright (C) 2002-2005 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 */
8
9#include "ipf.h"
10
11#define	PRINTF	(void)printf
12#define	FPRINTF	(void)fprintf
13
14
15iphtable_t *printhash(hp, copyfunc, name, opts)
16iphtable_t *hp;
17copyfunc_t copyfunc;
18char *name;
19int opts;
20{
21	iphtent_t *ipep, **table;
22	iphtable_t iph;
23	int printed;
24	size_t sz;
25
26	if ((*copyfunc)((char *)hp, (char *)&iph, sizeof(iph)))
27		return NULL;
28
29	if ((name != NULL) && strncmp(name, iph.iph_name, FR_GROUPLEN))
30		return iph.iph_next;
31
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);
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