lshd.c 1.96 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1 2 3
/* lshd.c
 *
 * main server program.
4 5
 *
 * $Id$ */
Niels Möller's avatar
Niels Möller committed
6

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/* lsh, an implementation of the ssh protocol
 *
 * Copyright (C) 1998 Niels Mller
 *
 * 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 the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
<
Niels Möller's avatar
Niels Möller committed
26 27 28 29
#include <stdio.h>
#include <locale.h>

#include "getopt.h"
Niels Möller's avatar
Niels Möller committed
30 31 32 33 34

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

Niels Möller's avatar
Niels Möller committed
35 36
#define BLOCK_SIZE 32768

Niels Möller's avatar
Niels Möller committed
37 38 39 40 41 42 43 44 45 46 47 48
/* Global variable */
struct io_backend backend;

void usage() NORETURN;

void usage()
{
  exit(1);
}

int main(int argc, char **argv)
{
49
  char *host = NULL;  /* Interface to bind */
Niels Möller's avatar
Niels Möller committed
50 51 52
  char *port = "ssh";
  int option;

53 54
  struct sockaddr_in local;
    
Niels Möller's avatar
Niels Möller committed
55 56 57 58
  /* 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
59
  while((option = getopt(argc, argv, "dp:qi:v")) != -1)
Niels Möller's avatar
Niels Möller committed
60 61 62 63 64 65 66 67 68 69 70
    switch(option)
      {
      case 'p':
	port = optarg;
	break;
      case 'q':
	quiet_flag = 1;
	break;
      case 'd':
	debug_flag = 1;
	break;
71 72 73
      case 'i':
	host = optarg;
	break;
Niels Möller's avatar
Niels Möller committed
74 75 76
      case 'v':
	verbose_flag = 1;
	break;
Niels Möller's avatar
Niels Möller committed
77 78 79 80 81 82 83
      default:
	usage();
      }

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

84
  if (!get_inaddr(&local, host, port, "tcp"))
Niels Möller's avatar
Niels Möller committed
85 86 87 88 89
    {
      fprintf(stderr, "No such host or service");
      exit(1);
    }

Niels Möller's avatar
Niels Möller committed
90 91 92 93
  io_listen(&backend, &local, 
	    make_server_callback(&backend,
				 "lsh - a free ssh",
				 BLOCK_SIZE));
Niels Möller's avatar
Niels Möller committed
94
  
Niels Möller's avatar
Niels Möller committed
95
  io_run(&backend);
Niels Möller's avatar
Niels Möller committed
96 97 98

  return 0;
}