txtinfo: simplify printing HNAs
authorFerry Huberts <ferry.huberts@pelagic.nl>
Sun, 21 Feb 2016 10:54:02 +0000 (11:54 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Sun, 21 Feb 2016 12:23:40 +0000 (13:23 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/txtinfo/src/olsrd_txtinfo.c

index 2dc3973..fc1712d 100644 (file)
@@ -293,42 +293,49 @@ void ipc_print_hna(struct autobuf *abuf) {
   struct ip_prefix_list *hna;
   struct hna_entry *tmp_hna;
   struct ipaddr_str prefixbuf;
-  struct ipaddr_str mainaddrbuf;
+  struct ipaddr_str gwaddrbuf;
 
+  const char * field;
   if (vtime) {
-    abuf_puts(abuf, "Table: HNA\nDestination\tGateway\tVTime\n");
+    field = "\tVTime";
   } else {
-    abuf_puts(abuf, "Table: HNA\nDestination\tGateway\n");
+    field = "";
   }
 
+  abuf_puts(abuf, "Table: HNA\n");
+  abuf_appendf(abuf, "Destination\tGateway%s\n", field);
+
   /* Announced HNA entries */
   for (hna = olsr_cnf->hna_entries; hna != NULL ; hna = hna->next) {
-    abuf_appendf(abuf, "%s/%d\t%s\n",
-        olsr_ip_to_string(&prefixbuf, &hna->net.prefix),
-        hna->net.prefix_len,
-        olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
+    abuf_appendf(abuf, "%s/%d\t%s",
+      olsr_ip_to_string(&prefixbuf, &hna->net.prefix),
+      hna->net.prefix_len,
+      olsr_ip_to_string(&gwaddrbuf, &olsr_cnf->main_addr));
+
+      if (vtime) {
+        abuf_appendf(abuf, "\t%u.%03u", 0, 0);
+      }
+      abuf_puts(abuf, "\n");
   }
 
   /* HNA entries */
-  OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna)
-        {
-          struct hna_net *tmp_net;
-
-          /* Check all networks */
-          for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
-            abuf_appendf(abuf, "%s/%d\t%s",
-                olsr_ip_to_string(&prefixbuf, &tmp_net->hna_prefix.prefix),
-                tmp_net->hna_prefix.prefix_len,
-                olsr_ip_to_string(&mainaddrbuf, &tmp_hna->A_gateway_addr));
-            if (vtime) {
-              uint32_t vt = tmp_net->hna_net_timer ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0;
-              abuf_appendf(abuf, "\t\%u.%03u\n", vt / 1000, abs(vt % 1000));
-            } else {
-              abuf_puts(abuf, "\n");
-            }
-          }
-        }OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
-
+  OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna) {
+    struct hna_net *tmp_net;
+
+    /* Check all networks */
+    for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
+      abuf_appendf(abuf, "%s/%d\t%s",
+        olsr_ip_to_string(&prefixbuf, &tmp_net->hna_prefix.prefix),
+        tmp_net->hna_prefix.prefix_len,
+        olsr_ip_to_string(&gwaddrbuf, &tmp_hna->A_gateway_addr));
+
+      if (vtime) {
+        unsigned int diff = tmp_net->hna_net_timer ? (unsigned int) (tmp_net->hna_net_timer->timer_clock - now_times) : 0;
+        abuf_appendf(abuf, "\t%u.%03u", diff / 1000, diff % 1000);
+      }
+      abuf_puts(abuf, "\n");
+    }
+  } OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
   abuf_puts(abuf, "\n");
 }