aboutsummaryrefslogtreecommitdiffstats
path: root/src/fnettrace/radix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fnettrace/radix.c')
-rw-r--r--src/fnettrace/radix.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/fnettrace/radix.c b/src/fnettrace/radix.c
index f0ac4c094..322ee2643 100644
--- a/src/fnettrace/radix.c
+++ b/src/fnettrace/radix.c
@@ -151,12 +151,22 @@ RNode *radix_longest_prefix_match(uint32_t ip) {
151} 151}
152 152
153static uint32_t sum; 153static uint32_t sum;
154static void print(RNode *ptr, int level) { 154static void print(RNode *ptr, int level, int pkts) {
155 if (!ptr) 155 if (!ptr)
156 return; 156 return;
157 if (ptr->name) { 157 if (ptr->name) {
158 printf("%d.%d.%d.%d/%d ", PRINT_IP(sum << (32 - level)), level); 158 if (pkts) {
159 printf("%s\n", ptr->name); 159 if (ptr->pkts) {
160 printf(" %d.%d.%d.%d/%d ", PRINT_IP(sum << (32 - level)), level);
161 printf("%s", ptr->name);
162 printf(" (%u)\n", ptr->pkts);
163 }
164 }
165 else {
166 printf("%d.%d.%d.%d/%d ", PRINT_IP(sum << (32 - level)), level);
167 printf("%s", ptr->name);
168 printf("\n");
169 }
160 } 170 }
161 171
162 if (ptr->zero == NULL && ptr->one == NULL) 172 if (ptr->zero == NULL && ptr->one == NULL)
@@ -164,22 +174,21 @@ static void print(RNode *ptr, int level) {
164 174
165 level++; 175 level++;
166 sum <<= 1; 176 sum <<= 1;
167 print(ptr->zero, level); 177 print(ptr->zero, level, pkts);
168 sum++; 178 sum++;
169 print(ptr->one, level); 179 print(ptr->one, level, pkts);
170 sum--; 180 sum--;
171 sum >>= 1; 181 sum >>= 1;
172} 182}
173 183
174void radix_print(void) { 184void radix_print(int pkts) {
175 if (!head) 185 if (!head)
176 return; 186 return;
177 printf("\n");
178 sum = 0; 187 sum = 0;
179 print(head->zero, 1); 188 print(head->zero, 1, pkts);
180 assert(sum == 0); 189 assert(sum == 0);
181 sum = 1; 190 sum = 1;
182 print(head->one, 1); 191 print(head->one, 1, pkts);
183 assert(sum == 1); 192 assert(sum == 1);
184} 193}
185 194