summaryrefslogtreecommitdiffstats
path: root/net_keypad.c
blob: 9169b8061e0e34a12a6d72ef3b2a548f9c9b4e37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "util.h"
#include "keypad.h"




static int usage (const char *name)
{
  fprintf (stderr, "Usage:\n");
  fprintf (stderr, "%s -h host [-p port]\n", name);
  fprintf (stderr, "\n");

  return -1;
}


int main (int argc, char *argv[])
{
  unsigned opt;
  const char *host = NULL;
  unsigned port = 10001;
  int fd;

  while ((opt = getopt (argc, argv, "h:p:z:USPRBFTAD")) != -1) {
    switch (opt) {
    case 'h':
      host = optarg;
      break;

    case 'p':
      port = atoi (optarg);
      break;

    default: /* '?' */
      return usage (argv[0]);
    }
  }

  if (!host) return (usage (argv[0]));

  fd = open_tcp_client (host, port);

  if (fd < 0) {
    perror ("open tcp port");
    return -1;
  }

  return gd_keypad (fd);
}