-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommandline_parser.h
82 lines (64 loc) · 1.29 KB
/
commandline_parser.h
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef PORT_PROTECTION_COMMANDLINEPARSER_H
#define PORT_PROTECTION_COMMANDLINEPARSER_H
#include <stdbool.h>
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
static const int MAX_STR_LEN = 254;
static const int MAX_PARAM_LEN = 15;
typedef unsigned short ushort;
typedef enum {
OK = 0,
NOT_ENOUGH_ARG,
BAD_PORT_NUMBER,
BAD_INTERFACE,
BAD_KEY_TOO_LONG,
BAD_KEY_FILE,
UNKNOWN_ERROR,
UNKNOWN_PARAM,
BAD_CONFIG_FILE
} ParseErrorCode;
typedef enum {
TCP,
UDP
} Protocol;
typedef struct {
bool verbose;
ushort listen_port;
ushort protect_port;
char *interface_name;
char *key;
char *cert_file;
char *key_file;
ParseErrorCode error_code;
Protocol protocol;
} Argument;
#include "debug.h"
#include "config_parser.h"
/**
* check if interface exists
* @param interface
* @return
*/
bool check_interface(char *interface);
/**
* read key from file
* @param file
* @return key
*/
char *read_key(char *file);
/**
* parse arguments
* @param argc from main
* @param argv from main
* @return parsed args, error code in Argument.errorCode
*/
Argument *parse_args(int argc, char *argv[]);
/**
* free argument
* @param arg to free
*/
void free_arg(Argument *arg);
void print_arg(Argument *arg);
#endif