lshd.c 1.19 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* lshd.c
 *
 * main server program.
 */

#include <getopt.h>

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

/* Global variable */
struct io_backend backend;

void usage() NORETURN;

void usage()
{
  exit(1);
}

int main(int argc, char **argv)
{
24
  char *host = NULL;  /* Interface to bind */
Niels Möller's avatar
Niels Möller committed
25
26
27
28
  char *port = "ssh";
  int verbose;
  int option;

29
30
  struct sockaddr_in local;
    
Niels Möller's avatar
Niels Möller committed
31
32
33
34
  /* For filtering messages. Could perhaps also be used when converting
   * strings to and from UTF8. */
  setlocale(LC_CTYPE, "");
  
35
  while((option = getopt(argc, argv, "dp:qi:")) != -1)
Niels Möller's avatar
Niels Möller committed
36
37
38
39
40
41
42
43
44
45
46
    switch(option)
      {
      case 'p':
	port = optarg;
	break;
      case 'q':
	quiet_flag = 1;
	break;
      case 'd':
	debug_flag = 1;
	break;
47
48
49
      case 'i':
	host = optarg;
	break;
Niels Möller's avatar
Niels Möller committed
50
51
52
53
54
55
56
      default:
	usage();
      }

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

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

  {
    struct server_callback connected = {
      { (fd_callback_f) server_initiate },
      &backend,
      BLOCK_SIZE;
    };

70
71
    io_listen(&backend, &local, 
	      make_server_callback(backend, BLOCK_SIZE));
Niels Möller's avatar
Niels Möller committed
72
73
74
75
76
77
  }
  
  io_run();

  return 0;
}