Move /var/svc/log to /var/log/svc
[unleashed/lotheac.git] / usr / src / cmd / ipf / lib / common / printhash.c
blob034c952d6f62c5c8c731fb9db53357fa6b4df9f2
1 /*
2 * Copyright (C) 2002 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
7 * Use is subject to license terms.
8 */
10 #pragma ident "%Z%%M% %I% %E% SMI"
12 #include "ipf.h"
14 #define PRINTF (void)printf
15 #define FPRINTF (void)fprintf
18 iphtable_t *printhash(hp, copyfunc, name, opts)
19 iphtable_t *hp;
20 copyfunc_t copyfunc;
21 char *name;
22 int opts;
24 iphtent_t *ipep, **table;
25 iphtable_t iph;
26 int i, printed;
27 size_t sz;
29 if ((*copyfunc)((char *)hp, (char *)&iph, sizeof(iph)))
30 return NULL;
32 if ((name != NULL) && strncmp(name, iph.iph_name, FR_GROUPLEN))
33 return iph.iph_next;
35 if ((opts & OPT_DEBUG) == 0) {
36 if ((iph.iph_type & IPHASH_ANON) == IPHASH_ANON)
37 PRINTF("# 'anonymous' table\n");
38 switch (iph.iph_type & ~IPHASH_ANON)
40 case IPHASH_LOOKUP :
41 PRINTF("table");
42 break;
43 case IPHASH_GROUPMAP :
44 PRINTF("group-map");
45 if (iph.iph_flags & FR_INQUE)
46 PRINTF(" in");
47 else if (iph.iph_flags & FR_OUTQUE)
48 PRINTF(" out");
49 else
50 PRINTF(" ???");
51 break;
52 default :
53 PRINTF("%#x", iph.iph_type);
54 break;
56 PRINTF(" role = ");
57 } else {
58 PRINTF("Hash Table Number: %s", iph.iph_name);
59 if ((iph.iph_type & IPHASH_ANON) == IPHASH_ANON)
60 PRINTF("(anon)");
61 putchar(' ');
62 PRINTF("Role: ");
65 switch (iph.iph_unit)
67 case IPL_LOGNAT :
68 PRINTF("nat");
69 break;
70 case IPL_LOGIPF :
71 PRINTF("ipf");
72 break;
73 case IPL_LOGAUTH :
74 PRINTF("auth");
75 break;
76 case IPL_LOGCOUNT :
77 PRINTF("count");
78 break;
79 default :
80 PRINTF("#%d", iph.iph_unit);
81 break;
84 if ((opts & OPT_DEBUG) == 0) {
85 if ((iph.iph_type & ~IPHASH_ANON) == IPHASH_LOOKUP)
86 PRINTF(" type = hash");
87 PRINTF(" number = %s size = %lu",
88 iph.iph_name, (u_long)iph.iph_size);
89 if (iph.iph_seed != 0)
90 PRINTF(" seed = %lu", iph.iph_seed);
91 putchar('\n');
92 } else {
93 PRINTF(" Type: ");
94 switch (iph.iph_type & ~IPHASH_ANON)
96 case IPHASH_LOOKUP :
97 PRINTF("lookup");
98 break;
99 case IPHASH_GROUPMAP :
100 PRINTF("groupmap Group. %s", iph.iph_name);
101 break;
102 default :
103 break;
106 putchar('\n');
107 PRINTF("\t\tSize: %lu\tSeed: %lu",
108 (u_long)iph.iph_size, iph.iph_seed);
109 PRINTF("\tRef. Count: %d\tMasks: %#x\n", iph.iph_ref,
110 iph.iph_masks[3]);
113 if ((opts & OPT_DEBUG) != 0) {
114 struct in_addr m;
116 for (i = 0; i < 32; i++) {
117 if ((1 << i) & iph.iph_masks[3]) {
118 ntomask(4, i, &m.s_addr);
119 PRINTF("\t\tMask: %s\n", inet_ntoa(m));
124 if ((opts & OPT_DEBUG) == 0)
125 PRINTF("\t{");
127 sz = iph.iph_size * sizeof(*table);
128 table = malloc(sz);
129 if ((*copyfunc)((char *)iph.iph_table, (char *)table, sz))
130 return NULL;
132 for (i = 0, printed = 0; i < iph.iph_size; i++) {
133 for (ipep = table[i]; ipep != NULL; ) {
134 ipep = printhashnode(&iph, ipep, copyfunc, opts);
135 printed++;
138 if (printed == 0)
139 putchar(';');
141 free(table);
143 if ((opts & OPT_DEBUG) == 0)
144 PRINTF(" };\n");
146 return iph.iph_next;