summaryrefslogtreecommitdiffstats
path: root/main.c
blob: 36006af7f4fd0652fb1a7d8ff63b561406e5f677 (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
57
58
59
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <getopt.h>
#include "client.h"
#include "server.h"

void usage(char exname[])
	{
	fprintf(stderr,"Usage: %s [OPTIONS]\n\
        -h,	--help		This help message.\n\
        -c,	--client	Enable client mode (default).\n\
        -s,	--server	Enable server mode.\n", exname);

        exit(0);
        }

int main(int argc, char *argv[])
	{
	static struct option long_options[] =
		{
		{"help", no_argument, 0, 'h'},
		{"client", no_argument, 0, 'c'},
		{"server", no_argument, 0, 's'},
		{0,0,0,0}
		};

	bool isClient = true;
	/* go through the options */
	while(1)
		{
		int option_index = 0;
		char c = getopt_long(argc, argv, "hcs", long_options, &option_index);
		/* End of args */
		if (c == -1){break;}
		switch (c)
			{
			case 'h':
				usage(argv[0]);
				break;
			case 'c':
				isClient = true;
				break;
			case 's':
				isClient = false;
				break;
			case '?':
				break;
			default:
				exit(1);
			}
		}

	/* pass off to client and server */
	if (isClient){client();}
	else {server();}

	return 0;
	}