lshd.c 2.1 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
/* 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
25 26

#include <errno.h>
Niels Möller's avatar
Niels Möller committed
27
#include <locale.h>
Niels Möller's avatar
Niels Möller committed
28 29
#include <stdio.h>
#include <string.h>
Niels Möller's avatar
Niels Möller committed
30 31

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

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

Niels Möller's avatar
Niels Möller committed
37 38
#define BLOCK_SIZE 32768

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

void usage() NORETURN;

void usage()
{
  exit(1);
}

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

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

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

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

Niels Möller's avatar
Niels Möller committed
92
  if (!io_listen(&backend, &local, 
Niels Möller's avatar
Niels Möller committed
93 94
	    make_server_callback(&backend,
				 "lsh - a free ssh",
Niels Möller's avatar
Niels Möller committed
95 96 97 98 99
				 BLOCK_SIZE)))
    {
      werror("lsh: Connection failed: %s\n", strerror(errno));
      return 1;
    }
Niels Möller's avatar
Niels Möller committed
100
  
Niels Möller's avatar
Niels Möller committed
101
  io_run(&backend);
Niels Möller's avatar
Niels Möller committed
102 103 104

  return 0;
}