]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ipfilter/lib/printhashnode.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ipfilter / lib / printhashnode.c
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 iphtent_t *
13 printhashnode(iph, ipep, copyfunc, opts, fields)
14         iphtable_t *iph;
15         iphtent_t *ipep;
16         copyfunc_t copyfunc;
17         int opts;
18         wordtab_t *fields;
19 {
20         iphtent_t ipe;
21         u_int hv;
22         int i;
23
24         if ((*copyfunc)(ipep, &ipe, sizeof(ipe)))
25                 return NULL;
26
27         hv = IPE_V4_HASH_FN(ipe.ipe_addr.i6[0], ipe.ipe_mask.i6[0],
28                             iph->iph_size);
29
30         if (fields != NULL) {
31                 for (i = 0; fields[i].w_value != 0; i++) {
32                         printpoolfield(&ipe, IPLT_HASH, i);
33                         if (fields[i + 1].w_value != 0)
34                                 printf("\t");
35                 }
36                 printf("\n");
37         } else if ((opts & OPT_DEBUG) != 0) {
38                 PRINTF("\t%d\tAddress: %s", hv,
39                         inet_ntoa(ipe.ipe_addr.in4));
40                 printmask(ipe.ipe_family, (u_32_t *)&ipe.ipe_mask.in4_addr);
41                 PRINTF("\tRef. Count: %d\tGroup: %s\n", ipe.ipe_ref,
42                         ipe.ipe_group);
43 #ifdef USE_QUAD_T
44                 PRINTF("\tHits: %"PRIu64"\tBytes: %"PRIu64"\n",
45                        ipe.ipe_hits, ipe.ipe_bytes);
46 #else
47                 PRINTF("\tHits: %lu\tBytes: %lu\n",
48                        ipe.ipe_hits, ipe.ipe_bytes);
49 #endif
50         } else {
51                 putchar(' ');
52                 printip(ipe.ipe_family, (u_32_t *)&ipe.ipe_addr.in4_addr);
53                 printmask(ipe.ipe_family, (u_32_t *)&ipe.ipe_mask.in4_addr);
54                 if (ipe.ipe_value != 0) {
55                         switch (iph->iph_type & ~IPHASH_ANON)
56                         {
57                         case IPHASH_GROUPMAP :
58                                 if (strncmp(ipe.ipe_group, iph->iph_name,
59                                             FR_GROUPLEN))
60                                         PRINTF(", group=%s", ipe.ipe_group);
61                                 break;
62                         }
63                 }
64                 putchar(';');
65         }
66
67         ipep = ipe.ipe_next;
68         return ipep;
69 }