lsh.c 1.39 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1 2 3 4 5
/* lsh.c
 *
 * client main program
 */

Niels Möller's avatar
Niels Möller committed
6 7 8 9
#include <stdio.h>
#include <locale.h>

#include "getopt.h"
Niels Möller's avatar
Niels Möller committed
10 11 12 13

#include "io.h"
#include "werror.h"
#include "client.h"
Niels Möller's avatar
Niels Möller committed
14 15 16
#include "format.h"
#include "crypto.h"
#include "xalloc.h"
Niels Möller's avatar
Niels Möller committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

#define BLOCK_SIZE 32768

/* Global variable */
struct io_backend backend;

void usage() NORETURN;

void usage()
{
  exit(1);
}

int main(int argc, char **argv)
{
  char *host = NULL;
  char *port = "ssh";
  int option;

Niels Möller's avatar
Niels Möller committed
36 37
  struct lsh_string *random_seed;
  
Niels Möller's avatar
Niels Möller committed
38
  struct sockaddr_in remote;
Niels Möller's avatar
Niels Möller committed
39 40 41 42

  /* For filtering messages. Could perhaps also be used when converting
   * strings to and from UTF8. */
  setlocale(LC_CTYPE, "");
Niels Möller's avatar
Niels Möller committed
43
  
Niels Möller's avatar
Niels Möller committed
44
  while((option = getopt(argc, argv, "dp:qv")) != -1)
Niels Möller's avatar
Niels Möller committed
45 46 47 48 49 50 51 52 53 54 55
    switch(option)
      {
      case 'p':
	port = optarg;
	break;
      case 'q':
	quiet_flag = 1;
	break;
      case 'd':
	debug_flag = 1;
	break;
Niels Möller's avatar
Niels Möller committed
56 57 58
      case 'v':
	verbose_flag = 1;
	break;
Niels Möller's avatar
Niels Möller committed
59 60 61 62 63 64 65 66 67 68 69
      default:
	usage();
      }

  if ( (argc - optind) < 1)
    usage();

  host = argv[optind];

  if (!get_inaddr(&remote, host, port, "tcp"))
    {
Niels Möller's avatar
Niels Möller committed
70
      fprintf(stderr, "No such host or service\n");
Niels Möller's avatar
Niels Möller committed
71 72 73
      exit(1);
    }

Niels Möller's avatar
Niels Möller committed
74 75
  random_seed = ssh_format("%z", "gazonk");
  
Niels Möller's avatar
Niels Möller committed
76
  io_connect(&backend, &remote, NULL,
Niels Möller's avatar
Niels Möller committed
77 78
	     make_client_callback(&backend,
				  "lsh - a free ssh",
Niels Möller's avatar
Niels Möller committed
79 80 81 82 83
				  BLOCK_SIZE,
				  make_poor_random(&sha_algorithm,
						   random_seed)));

  lsh_string_free(random_seed);
Niels Möller's avatar
Niels Möller committed
84
  
Niels Möller's avatar
Niels Möller committed
85
  io_run(&backend);
Niels Möller's avatar
Niels Möller committed
86 87 88 89 90

  return 0;
}