]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
--csv allows multiple service names as arguments
authorVaibhav Bajpai <contact@vaibhavbajpai.com>
Sun, 5 May 2013 12:44:46 +0000 (14:44 +0200)
committerR.E. Wolff <R.E.Wolff@BitWizard.nl>
Mon, 13 May 2013 15:22:54 +0000 (17:22 +0200)
display.c
display.h
mtr.c
report.c
report.h

index ee3934d09a9067ca3a84d7857fdb7100102b5cb2..cc5cd5966789c9965039de26765f63fa38e21e69 100644 (file)
--- a/display.c
+++ b/display.c
@@ -112,7 +112,7 @@ void display_open(void)
 }
 
 
-void display_close(void)
+void display_close(time_t now)
 {
   switch(DisplayMode) {
   case DisplayReport:
@@ -125,7 +125,7 @@ void display_close(void)
     xml_close();
     break;
   case DisplayCSV:
-    csv_close();
+    csv_close(now);
     break;
   case DisplayCurses:
 #ifndef NO_IPINFO
index 486e25dde912fc0614b9fa88a0624eabadea0b96..4ed2d66db1255b11517cb42c7df2af0fdc57f55f 100644 (file)
--- a/display.h
+++ b/display.h
@@ -32,7 +32,7 @@ enum { DisplayReport, DisplayCurses, DisplayGTK, DisplaySplit,
 /*  Prototypes for display.c  */
 void display_detect(int *argc, char ***argv);
 void display_open(void);
-void display_close(void);
+void display_close(time_t now);
 void display_redraw(void);
 void display_rawping(int hostnum, int msec);
 void display_rawhost(int hostnum, ip_t *ip_addr);
diff --git a/mtr.c b/mtr.c
index 39a618fe32c83a896558222123c7983999add17f..7c6feeb782d9fcf5e09008c80059bd1ef9dcfcad 100644 (file)
--- a/mtr.c
+++ b/mtr.c
@@ -26,6 +26,7 @@
 #include <sys/socket.h> 
 #include <unistd.h>
 #include <strings.h>
+#include <time.h>
 
 #include "mtr.h"
 #include "mtr-curses.h"
@@ -348,11 +349,6 @@ void parse_arg (int argc, char **argv)
   if (optind > argc - 1)
     return;
 
-  Hostname = argv[optind++];
-
-  if (argc > optind) {
-    cpacketsize = atoi (argv[optind]);
-  }
 }
 
 
@@ -446,84 +442,93 @@ int main(int argc, char **argv)
 #endif
            "\t\t[--psize=bytes/-s bytes]\n"            /* ok */
            "\t\t[--report-wide|-w] [-u|-T] [--port=PORT] [--timeout=SECONDS]\n"            /* rew */
-          "\t\t[--interval=SECONDS] HOSTNAME [PACKETSIZE]\n", argv[0]);
+          "\t\t[--interval=SECONDS] HOSTNAME\n", argv[0]);
     exit(0);
   }
 
-  if (Hostname == NULL) Hostname = "localhost";
+  time_t now = time(NULL);
 
-  if (gethostname(LocalHostname, sizeof(LocalHostname))) {
-       strcpy(LocalHostname, "UNKNOWNHOST");
-  }
+  while (optind < argc ) {
 
-  if (net_preopen_result != 0) {
-    fprintf(stderr, "mtr: Unable to get raw socket.  (Executable not suid?)\n");
-    exit(1);
-  }
+    Hostname = argv[optind++];
+    if (Hostname == NULL) Hostname = "localhost";
+    if (gethostname(LocalHostname, sizeof(LocalHostname))) {
+    strcpy(LocalHostname, "UNKNOWNHOST");
+    }
+
+    if (net_preopen_result != 0) {
+      fprintf(stderr, "mtr: Unable to get raw socket.  (Executable not suid?)\n");
+      exit(1);
+    }
 
 #ifdef ENABLE_IPV6
-  /* gethostbyname2() is deprecated so we'll use getaddrinfo() instead. */
-  bzero( &hints, sizeof hints );
-  hints.ai_family = af;
-  hints.ai_socktype = SOCK_DGRAM;
-  error = getaddrinfo( Hostname, NULL, &hints, &res );
-  if ( error ) {
-    if (error == EAI_SYSTEM)
-       perror ("Failed to resolve host");
-    else
-       fprintf (stderr, "Failed to resolve host: %s\n", gai_strerror(error));
-    exit( EXIT_FAILURE );
-  }
-  /* Convert the first addrinfo into a hostent. */
-  host = &trhost;
-  bzero( host, sizeof trhost );
-  host->h_name = res->ai_canonname;
-  host->h_aliases = NULL;
-  host->h_addrtype = res->ai_family;
-  af = res->ai_family;
-  host->h_length = res->ai_addrlen;
-  host->h_addr_list = alptr;
-  switch ( af ) {
-  case AF_INET:
-    sa4 = (struct sockaddr_in *) res->ai_addr;
-    alptr[0] = (void *) &(sa4->sin_addr);
-    break;
-  case AF_INET6:
-    sa6 = (struct sockaddr_in6 *) res->ai_addr;
-    alptr[0] = (void *) &(sa6->sin6_addr);
-    break;
-  default:
-    fprintf( stderr, "mtr unknown address type\n" );
-    exit( EXIT_FAILURE );
-  }
-  alptr[1] = NULL;
+    /* gethostbyname2() is deprecated so we'll use getaddrinfo() instead. */
+    bzero( &hints, sizeof hints );
+    hints.ai_family = af;
+    hints.ai_socktype = SOCK_DGRAM;
+    error = getaddrinfo( Hostname, NULL, &hints, &res );
+    if ( error ) {
+      if (error == EAI_SYSTEM)
+         perror ("Failed to resolve host");
+      else
+         fprintf (stderr, "Failed to resolve host: %s\n", gai_strerror(error));
+      exit( EXIT_FAILURE );
+    }
+    /* Convert the first addrinfo into a hostent. */
+    host = &trhost;
+    bzero( host, sizeof trhost );
+    host->h_name = res->ai_canonname;
+    host->h_aliases = NULL;
+    host->h_addrtype = res->ai_family;
+    af = res->ai_family;
+    host->h_length = res->ai_addrlen;
+    host->h_addr_list = alptr;
+    switch ( af ) {
+    case AF_INET:
+      sa4 = (struct sockaddr_in *) res->ai_addr;
+      alptr[0] = (void *) &(sa4->sin_addr);
+      break;
+    case AF_INET6:
+      sa6 = (struct sockaddr_in6 *) res->ai_addr;
+      alptr[0] = (void *) &(sa6->sin6_addr);
+      break;
+    default:
+      fprintf( stderr, "mtr unknown address type\n" );
+      exit( EXIT_FAILURE );
+    }
+    alptr[1] = NULL;
 #else
-    host = gethostbyname(Hostname);
-  if (host == NULL) {
-    herror("mtr gethostbyname");
-    exit(1);
-  }
-  af = host->h_addrtype;
+      host = gethostbyname(Hostname);
+    if (host == NULL) {
+      herror("mtr gethostbyname");
+      exit(1);
+    }
+    af = host->h_addrtype;
 #endif
 
-  if (net_open(host) != 0) {
-       fprintf(stderr, "mtr: Unable to start net module.\n");
-        exit(1);
-      }
+    if (net_open(host) != 0) {
+    fprintf(stderr, "mtr: Unable to start net module.\n");
+          exit(1);
+        }
 
-  if (net_set_interfaceaddress (InterfaceAddress) != 0) {
-    fprintf( stderr, "mtr: Couldn't set interface address.\n" ); 
-    exit( EXIT_FAILURE ); 
-  }
+    if (net_set_interfaceaddress (InterfaceAddress) != 0) {
+      fprintf( stderr, "mtr: Couldn't set interface address.\n" ); 
+      exit( EXIT_FAILURE ); 
+    }
+
+    display_open();
+    dns_open();
 
-  display_open();
-  dns_open();
+    display_mode = 0;
+    display_loop();
 
-  display_mode = 0;
-  display_loop();
+    net_end_transit();
+    display_close(now);
+
+    if ( DisplayMode != DisplayCSV ) break;
+
+  }
 
-  net_end_transit();
-  display_close();
   net_close();
 
   return 0;
index da1c1e334a35e2ac262d8baf5e34a6eda6354855..72e2f55175096bf62f2e95f8428868b1417fe742 100644 (file)
--- a/report.c
+++ b/report.c
@@ -344,12 +344,11 @@ char *trimwhitespace(char *str) {
 }
 
 
-void csv_close(void)
+void csv_close(time_t now)
 {
   int i, j, at, max;
   ip_t *addr;
   char name[81];
-  time_t now = time(NULL);
 
   for( i=0; i<MAXFLD; i++ ) {
       j = fld_index[fld_active[i]];
index 755c5968fa8e6572bc27032ae2f4c133d7281720..81c2d81385828dc09092dcc7f3c28c6f8a095c98 100644 (file)
--- a/report.h
+++ b/report.h
@@ -25,4 +25,4 @@ void txt_close(void);
 void xml_open(void);
 void xml_close(void);
 void csv_open(void);
-void csv_close(void);
+void csv_close(time_t now);