forked from nodogsplash/nodogsplash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommandline.c
126 lines (106 loc) · 3.14 KB
/
commandline.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
* *
\********************************************************************/
/** @file commandline.c
@brief Command line argument handling
@author Copyright (C) 2004 Philippe April <papril777@yahoo.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <syslog.h>
#include "debug.h"
#include "safe.h"
#include "conf.h"
static void usage(void);
/** @internal
* @brief Print usage
*
* Prints usage, called when nodogsplash is run with -h or with an unknown option
*/
static void
usage(void)
{
printf("Usage: nodogsplash [options]\n"
"\n"
" -c <path> Use configuration file\n"
" -f Run in foreground\n"
" -d <level> Debug level (%d-%d)\n"
" -s Log to syslog\n"
" -w <path> Ndsctl socket path\n"
" -h Print this help\n"
" -v Print version\n"
"\n", DEBUGLEVEL_MIN, DEBUGLEVEL_MAX
);
}
/** Uses getopt() to parse the command line and set configuration values
*/
void parse_commandline(int argc, char **argv)
{
int c;
s_config *config = config_get_config();
while (-1 != (c = getopt(argc, argv, "c:hfd:sw:vi:64"))) {
switch(c) {
case 'h':
usage();
exit(1);
break;
case 'c':
if (optarg) {
strncpy(config->configfile, optarg, sizeof(config->configfile)-1);
}
break;
case 'w':
if (optarg) {
free(config->ndsctl_sock);
config->ndsctl_sock = safe_strdup(optarg);
}
break;
case 'f':
config->daemon = 0;
break;
case 'd':
if (set_debuglevel(optarg)) {
printf("Could not set debuglevel to %d\n", atoi(optarg));
exit(1);
}
break;
case 's':
config->log_syslog = 1;
break;
case 'v':
printf("This is Nodogsplash version " VERSION "\n");
exit(1);
break;
case '4':
config->ip6 = 0;
break;
case '6':
printf("IPv6 is not supported yet\n");
exit(1);
config->ip6 = 1;
break;
default:
usage();
exit(1);
break;
}
}
}