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