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