]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
fixed default hostname
authorRoger Wolff <R.E.Wolff@BitWizard.nl>
Wed, 3 Jul 2013 10:00:28 +0000 (12:00 +0200)
committerRoger Wolff <R.E.Wolff@BitWizard.nl>
Wed, 3 Jul 2013 10:00:28 +0000 (12:00 +0200)
mtr.c

diff --git a/mtr.c b/mtr.c
index 75a3b060642c46ba7a249dc50aa4316c00189e2e..fd4705d0ce72df376bdc68487545e2a0f3bc3c53 100644 (file)
--- a/mtr.c
+++ b/mtr.c
@@ -141,7 +141,8 @@ append_to_names(const char* progname, const char* item) {
     fprintf(stderr, "%s: memory allocation failure\n", progname);
     exit(EXIT_FAILURE);
   }
-  name->name = strdup(item);
+  // prepared for adding NULL name, but decided against that in the end.
+  name->name = item?strdup(item):item;
   name->next = names;
   names = name;
 }
@@ -581,13 +582,16 @@ int main(int argc, char **argv)
   }
 
   time_t now = time(NULL);
+
+  if (!names) append_to_names (argv[0], "localhost"); // default: localhost. 
+
   names_t* head = names;
   while (names != NULL) {
 
     Hostname = names->name;
-    if (Hostname == NULL) Hostname = "localhost";
+    //  if (Hostname == NULL) Hostname = "localhost"; // no longer necessary.
     if (gethostname(LocalHostname, sizeof(LocalHostname))) {
-    strcpy(LocalHostname, "UNKNOWNHOST");
+      strcpy(LocalHostname, "UNKNOWNHOST");
     }
 
     if (net_preopen_result != 0) {