lshd.c 1.18 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1 2 3 4 5
/* lshd.c
 *
 * main server 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 14

#include "io.h"
#include "werror.h"
#include "server.h"

Niels Möller's avatar
Niels Möller committed
15 16
#define BLOCK_SIZE 32768

Niels Möller's avatar
Niels Möller committed
17 18 19 20 21 22 23 24 25 26 27 28
/* Global variable */
struct io_backend backend;

void usage() NORETURN;

void usage()
{
  exit(1);
}

int main(int argc, char **argv)
{
29
  char *host = NULL;  /* Interface to bind */
Niels Möller's avatar
Niels Möller committed
30 31 32
  char *port = "ssh";
  int option;

33 34
  struct sockaddr_in local;
    
Niels Möller's avatar
Niels Möller committed
35 36 37 38
  /* 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
39
  while((option = getopt(argc, argv, "dp:qi:v")) != -1)
Niels Möller's avatar
Niels Möller committed
40 41 42 43 44 45 46 47 48 49 50
    switch(option)
      {
      case 'p':
	port = optarg;
	break;
      case 'q':
	quiet_flag = 1;
	break;
      case 'd':
	debug_flag = 1;
	break;
51 52 53
      case 'i':
	host = optarg;
	break;
Niels Möller's avatar
Niels Möller committed
54 55 56
      case 'v':
	verbose_flag = 1;
	break;
Niels Möller's avatar
Niels Möller committed
57 58 59 60 61 62 63
      default:
	usage();
      }

  if ( (argc - optind) != 0)
    usage();

64
  if (!get_inaddr(&local, host, port, "tcp"))
Niels Möller's avatar
Niels Möller committed
65 66 67 68 69
    {
      fprintf(stderr, "No such host or service");
      exit(1);
    }

Niels Möller's avatar
Niels Möller committed
70 71 72 73
  io_listen(&backend, &local, 
	    make_server_callback(&backend,
				 "lsh - a free ssh",
				 BLOCK_SIZE));
Niels Möller's avatar
Niels Möller committed
74
  
Niels Möller's avatar
Niels Möller committed
75
  io_run(&backend);
Niels Möller's avatar
Niels Möller committed
76 77 78

  return 0;
}