]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
added aslookup patch from bug #701514
authorR.E. Wolff <R.E.Wolff@BitWizard.nl>
Tue, 5 Feb 2013 14:32:53 +0000 (15:32 +0100)
committerR.E. Wolff <R.E.Wolff@BitWizard.nl>
Tue, 5 Feb 2013 14:32:53 +0000 (15:32 +0100)
curses.c
mtr.c

index ed3b33dfac7f4f2ba3bb839a127d23742ecf52ca..0652e874bb9df5add3e5057055ee11f14d372473 100644 (file)
--- a/curses.c
+++ b/curses.c
@@ -63,6 +63,8 @@
 #include "display.h"
 #include "net.h"
 #include "dns.h"
+#include "asn.h"
+#include <glib.h>
 #endif
 
 #include <time.h>
@@ -312,6 +314,44 @@ void mtr_curses_hosts(int startstat)
     mpls = net_mpls(at);
 
     if( addrcmp( (void *) addr, (void *) &unspec_addr, af ) != 0 ) {
+      struct in6_addr addr6 = *addr;
+
+      if (PrintAS) {
+              u_char ipv4[4];
+              ipv4[0] = addr6.s6_addr[0];
+              ipv4[1] = addr6.s6_addr[1];
+              ipv4[2] = addr6.s6_addr[2];
+              ipv4[3] = addr6.s6_addr[3];
+
+#define NAMELEN 127
+              char ipv4_buf[NAMELEN];
+              char* chip = (char*) &ipv4_buf;
+              char* chas = NULL;
+              char** key_ptr = &chip;
+              char** value_ptr = &chas;
+
+
+              if (snprintf(ipv4_buf, NAMELEN, "%d.%d.%d.%d.asn.routeviews.org", ipv4[3],
+                                      ipv4[2], ipv4[1], ipv4[0]) >= NAMELEN) {
+                      return;
+              }
+
+
+
+              gboolean result =
+                      g_hash_table_lookup_extended
+                      (ashash, ipv4_buf, (gpointer*)key_ptr, (gpointer*)value_ptr);
+              if (!result) {
+                      char* as = asn_lookup(ipv4_buf);
+                      chip = (char*) strdup(ipv4_buf);
+                      chas = (char*) as;
+                      g_hash_table_insert(ashash, chip, chas);
+              }
+              //g_hash_table_destroy(hash);
+
+
+              printw("[AS%s] ", chas);
+      }
       name = dns_lookup(addr);
       if (! net_up(at))
        attron(A_BOLD);
@@ -604,6 +644,7 @@ void mtr_curses_redraw(void)
 
 void mtr_curses_open(void)
 {
+  ashash = g_hash_table_new(g_str_hash, g_str_equal);
   initscr();
   raw();
   noecho(); 
diff --git a/mtr.c b/mtr.c
index ff35b5180b6b933d3ba63ca63b8b23a22e9e1df8..fc01fc7e67fbeb9499cf19c9ca3f4c12427e5453 100644 (file)
--- a/mtr.c
+++ b/mtr.c
@@ -34,6 +34,7 @@
 #include "dns.h"
 #include "report.h"
 #include "net.h"
+#include "asn.h"
 
 
 #ifdef ENABLE_IPV6
@@ -152,6 +153,7 @@ void parse_arg (int argc, char **argv)
     { "udp", 0, 0, 'u' },      /* UDP (default is ICMP) */
     { "inet", 0, 0, '4' },     /* IPv4 only */
     { "inet6", 0, 0, '6' },    /* IPv6 only */
+    { "aslookup", 0, 0, 'z' },  /* Do AS lookup */
     { 0, 0, 0, 0 }
   };
 
@@ -287,6 +289,9 @@ void parse_arg (int argc, char **argv)
       fprintf( stderr, "IPv6 not enabled.\n" );
       break;
 #endif
+    case 'z':
+      PrintAS = 1;
+      break;
     }
   }
 
@@ -391,7 +396,7 @@ int main(int argc, char **argv)
     printf("usage: %s [-hvrwctglspniu46] [--help] [--version] [--report]\n"
           "\t\t[--report-wide] [--report-cycles=COUNT] [--curses] [--gtk]\n"
            "\t\t[--raw] [--split] [--mpls] [--no-dns] [--show-ips]\n"
-           "\t\t[--address interface]\n" /* BL */
+           "\t\t[--address interface]  [--aslookup]\n" /* BL */
            "\t\t[--psize=bytes/-s bytes]\n"            /* ok */
            "\t\t[--report-wide|-w] [-u]\n"            /* rew */
           "\t\t[--interval=SECONDS] HOSTNAME [PACKETSIZE]\n", argv[0]);