Give IP address instead of hex number when connecting tcp socket failed.
[tinc] / src / genauth.c
index 0d47d51..b727eb6 100644 (file)
@@ -1,6 +1,6 @@
 /*
     genauth.c -- generate a random passphrase
-    Copyright (C) 1998,99 Ivo Timmermans <zarq@iname.com>
+    Copyright (C) 1998,1999,2000 Ivo Timmermans <zarq@iname.com>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -35,12 +35,15 @@ int main(int argc, char **argv)
   int bits, c, i, bytes;
   unsigned char *p;
 
-  if(argc != 2)
+  if(argc > 2 || (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))))
     {
       fprintf(stderr, "Usage: %s bits\n", argv[0]);
       return 1;
     }
 
+  if(!argv[1])
+    argv[1] = "1024";
+  
   if(!(bits = atol(argv[1])))
     {
       fprintf(stderr, "Illegal number: %s\n", argv[1]);
@@ -60,7 +63,7 @@ int main(int argc, char **argv)
   p = xmalloc(bytes);
 
   setbuf(stdout, NULL);
-  for(i = 0; i < 128; i++)
+  for(i = 0; i < bytes; i++)
     {
       c = fgetc(fp);
       if(feof(fp))
@@ -70,23 +73,24 @@ int main(int argc, char **argv)
         }
       p[i] = c;
     }
+  fclose(fp);
 
-  for(i = 0; i < (bytes); i++)
+  if(isatty(1))
     {
-      c = fgetc(fp);
-      if(feof(fp))
-       {
-         puts("");
-         fprintf(stderr, "File was empty!\n");
-       }
-      p[i] = c;
+      fprintf(stderr, ": done.\nThe following line should be ENTIRELY copied into a passphrase file:\n");
+      printf("%d ", bits);
+      for(i = 0; i < bytes; i++)
+       printf("%02x", p[i]);
+      puts("");
+    }
+  else
+    {
+      printf("%d ", bits);
+      for(i = 0; i < bytes; i++)
+       printf("%02x", p[i]);
+      puts("");
+      fprintf(stderr, ": done.\n");
     }
-  fclose(fp);
-
-  printf("%d ", bits);
-  for(i = 0; i < bytes; i++)
-    printf("%02x", p[i]);
-  puts("");
 
   return 0;
 }