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