40 |
|
|
41 |
param_t param[PARAM_MAX] = { |
param_t param[PARAM_MAX] = { |
42 |
/* GENERAL CONFIGURATION */ |
/* GENERAL CONFIGURATION */ |
43 |
{opt_none, "access_method", string, false, {string:"modem"} |
{0, "access-method", "access_method", string, false, {string:"modem"} |
44 |
} |
} |
45 |
, |
, |
46 |
{opt_none, "protocol", string, false, {string:"aol30"} |
{0, "protocol", "protocol", string, false, {string:"aol30"} |
47 |
} |
} |
48 |
, |
, |
49 |
{opt_interface_type, "interface_type", string, false, {string:"tun"} |
{'t', "interface-type", "interface_type", string, false, {string:"tun"} |
50 |
} |
} |
51 |
, |
, |
52 |
{opt_interface_name, "interface_name", string, false, {string:NULL} |
{'i', "interface", "interface_name", string, false, {string:NULL} |
53 |
} |
} |
54 |
, |
, |
55 |
{opt_user, "user", string, false, {string:NULL} |
{'u', "user", "user", string, false, {string:NULL} |
56 |
} |
} |
57 |
, |
, |
58 |
{opt_pass, "pass", string, false, {string:NULL} |
{'p', "pass", "pass", string, false, {string:NULL} |
59 |
} |
} |
60 |
, |
, |
61 |
{opt_auto_reconnect, "auto_reconnect", boolean, false, {boolean:false} |
{'r', "auto-reconnect", "auto_reconnect", boolean, false, {boolean:false} |
62 |
} |
} |
63 |
, |
, |
64 |
{opt_none, "reconnect_delay", integer, false, {integer:0} |
{0, "reconnect-delay", "reconnect_delay", integer, false, {integer:0} |
65 |
} |
} |
66 |
, |
, |
67 |
{opt_daemon, "daemon", boolean, false, {boolean:false} |
{'d', "daemon", "daemon", boolean, false, {boolean:false} |
68 |
} |
} |
69 |
, |
, |
70 |
{opt_debug_level, "debug_level", integer, false, {integer:-1} |
{'D', "debug-level", "debug_level", integer, false, {integer:-1} |
71 |
} |
} |
72 |
, |
, |
73 |
{opt_none, "set_dns", boolean, false, {boolean:true} |
{0, "dns", "set_dns", boolean, false, {boolean:true} |
74 |
} |
} |
75 |
, |
, |
76 |
{opt_pid_file, "pid_file", string, false, {string:"/var/run/pengaol.pid"} |
{0, "pid-file", "pid_file", string, false, {string:"/var/run/pengaol.pid"} |
77 |
} |
} |
78 |
, |
, |
79 |
{opt_ip_up, "ip-up_script", string, false, {string:NULL} |
{0, "ip-up", "ip-up_script", string, false, {string:"/etc/pengaol/ip-up"} |
80 |
} |
} |
81 |
, |
, |
82 |
{opt_ip_down, "ip-down_script", string, false, {string:NULL} |
{0, "ip-down", "ip-down_script", string, false, {string:"/etc/pengaol/ip-down"} |
83 |
} |
} |
84 |
, |
, /* MODEM SPECIFIC */ |
85 |
|
{'m', "modem", "modem_device", string, false, {string:"/dev/modem"} |
|
/* MODEM SPECIFIC */ |
|
|
{opt_modem, "modem_device", string, false, {string:"/dev/modem"} |
|
86 |
} |
} |
87 |
, |
, |
88 |
{opt_rtscts, "rtscts", boolean, false, {boolean:true} |
{0, "rtscts", "rtscts", boolean, false, {boolean:true} |
89 |
} |
} |
90 |
, |
, |
91 |
{opt_init_str, "initstr1", string, false, {string:"ATZ"} |
{0, "init-str", "initstr1", string, false, {string:"ATZ"} |
92 |
} |
} |
93 |
, |
, |
94 |
{opt_none, "initstr2", string, false, {string:NULL} |
{0, NULL, "initstr2", string, false, {string:NULL} |
95 |
} |
} |
96 |
, |
, |
97 |
{opt_none, "initstr3", string, false, {string:NULL} |
{0, NULL, "initstr3", string, false, {string:NULL} |
98 |
} |
} |
99 |
, |
, |
100 |
{opt_none, "initstr4", string, false, {string:NULL} |
{0, NULL, "initstr4", string, false, {string:NULL} |
101 |
} |
} |
102 |
, |
, |
103 |
{opt_none, "initstr5", string, false, {string:NULL} |
{0, NULL, "initstr5", string, false, {string:NULL} |
104 |
} |
} |
105 |
, |
, |
106 |
{opt_none, "initstr6", string, false, {string:NULL} |
{0, NULL, "initstr6", string, false, {string:NULL} |
107 |
} |
} |
108 |
, |
, |
109 |
{opt_none, "initstr7", string, false, {string:NULL} |
{0, NULL, "initstr7", string, false, {string:NULL} |
110 |
} |
} |
111 |
, |
, |
112 |
{opt_none, "initstr8", string, false, {string:NULL} |
{0, NULL, "initstr8", string, false, {string:NULL} |
113 |
} |
} |
114 |
, |
, |
115 |
{opt_none, "initstr9", string, false, {string:NULL} |
{0, NULL, "initstr9", string, false, {string:NULL} |
116 |
} |
} |
117 |
, |
, |
118 |
{opt_dial_str, "dialstr", string, false, {string:"ATDT"} |
{0, "dial-str", "dialstr", string, false, {string:"ATDT"} |
119 |
} |
} |
120 |
, |
, |
121 |
{opt_none, "dial_prefix", string, false, {string:NULL} |
{0, NULL, "dial_prefix", string, false, {string:NULL} |
122 |
} |
} |
123 |
, |
, |
124 |
{opt_phone, "phone", string, false, {string:NULL} |
{'n', "phone", "phone", string, false, {string:NULL} |
125 |
} |
} |
126 |
, |
, |
127 |
{opt_none, "phone1", string, false, {string:NULL} |
{0, NULL, "phone1", string, false, {string:NULL} |
128 |
} |
} |
129 |
, |
, |
130 |
{opt_none, "phone2", string, false, {string:NULL} |
{0, NULL, "phone2", string, false, {string:NULL} |
131 |
} |
} |
132 |
, |
, |
133 |
{opt_none, "phone3", string, false, {string:NULL} |
{0, NULL, "phone3", string, false, {string:NULL} |
134 |
} |
} |
135 |
, |
, |
136 |
{opt_none, "phone4", string, false, {string:NULL} |
{0, NULL, "phone4", string, false, {string:NULL} |
137 |
} |
} |
138 |
, |
, |
139 |
{opt_none, "phone5", string, false, {string:NULL} |
{0, NULL, "phone5", string, false, {string:NULL} |
140 |
} |
} |
141 |
, |
, |
142 |
{opt_speed, "line_speed", integer, false, {integer:115200} |
{'s', "line-speed", "line_speed", integer, false, {integer:115200} |
143 |
} |
} |
144 |
, |
, |
145 |
{opt_none, "login_prompt", string, false, {string:"ogin:"} |
{0, NULL, "login_prompt", string, false, {string:"ogin:"} |
146 |
} |
} |
147 |
, |
, |
148 |
{opt_none, "server_pass_prompt", string, false, {string:"assword:"} |
{0, NULL, "server_pass_prompt", string, false, {string:"assword:"} |
149 |
} |
} |
150 |
, |
, |
151 |
{opt_server_login, "server_login", string, false, {string:"aol"} |
{'l', "server-login", "server_login", string, false, {string:"aol"} |
152 |
} |
} |
153 |
, |
, |
154 |
{opt_server_pass, "server_pass", string, false, {string:"aol"} |
{'w', "server-pass", "server_pass", string, false, {string:"aol"} |
155 |
} |
} |
156 |
, |
, |
157 |
{opt_none, "server_connected", string, false, {string:"onnected"} |
{0, NULL, "server_connected", string, false, {string:"onnected"} |
158 |
} |
} |
159 |
, |
, |
160 |
{opt_none, "server_bad_passwd", string, false, {string:"assword"} |
{0, NULL, "server_bad_passwd", string, false, {string:"assword"} |
161 |
} |
} |
162 |
, |
, |
163 |
{opt_none, "dial_retry", integer, false, {integer:3} |
{0, NULL, "dial_retry", integer, false, {integer:3} |
164 |
} |
} |
165 |
, |
, |
166 |
{opt_none, "retry_delay", integer, false, {integer:0} |
{0, NULL, "retry_delay", integer, false, {integer:0} |
167 |
} |
} |
168 |
, |
, |
169 |
{opt_none, "abort_busy", boolean, false, {boolean:true} |
{0, NULL, "abort_busy", boolean, false, {boolean:true} |
170 |
} |
} |
171 |
, |
, |
172 |
{opt_none, "abort_dialtone", boolean, false, {boolean:true} |
{0, NULL, "abort_dialtone", boolean, false, {boolean:true} |
173 |
} |
} |
174 |
, |
, /* CABLE SPECIFIC */ |
175 |
|
{0, NULL, "aol_host", string, false, {string:"americaonline.aol.com"} |
|
/* CABLE SPECIFIC */ |
|
|
{opt_none, "aol_host", string, false, {string:"americaonline.aol.com"} |
|
176 |
} |
} |
177 |
, |
, |
178 |
{opt_none, "aol_port", integer, false, {integer:5190} |
{0, NULL, "aol_port", integer, false, {integer:5190} |
179 |
} |
} |
180 |
, |
, |
181 |
{opt_none, "cable_iface", string, false, {string:"eth0"} |
{0, NULL, "cable_iface", string, false, {string:"eth0"} |
182 |
} |
} |
183 |
, |
, |
184 |
{opt_none, "connect_ip", string, false, {string:"0.0.0.0"} |
{0, NULL, "connect_ip", string, false, {string:"0.0.0.0"} |
185 |
} |
} |
186 |
}; |
}; |
187 |
|
|
188 |
|
|
189 |
/* |
/* |
190 |
* Command line options |
* Command line options |
191 |
*/ |
*/ |
192 |
|
|
193 |
/* Be sure to keep both sync. */ |
/* Extra options */ |
194 |
static const char short_options[] = "hVrt:i:u:p:dD:m:n:s:l:w:"; |
enum option_e |
195 |
|
{ |
196 |
|
opt_help = 'h', |
197 |
|
opt_version = 'V' |
198 |
|
}; |
199 |
|
|
200 |
int toto; |
/* short_options merged with generated ones. */ |
201 |
|
static const char short_options_head[] = "hV"; |
202 |
|
|
203 |
static struct option const long_options[] = |
/* long_options merged with generated ones. */ |
204 |
|
static struct option const long_options_head[] = |
205 |
{ |
{ |
206 |
{"help", no_argument, 0, opt_help}, |
{"help", no_argument, 0, opt_help}, |
207 |
{"version", no_argument, 0, opt_version}, |
{"version", no_argument, 0, opt_version}, |
|
{"interface-type", required_argument, 0, opt_interface_type}, |
|
|
{"interface_name", required_argument, 0, opt_interface_name}, |
|
|
{"user", required_argument, 0, opt_user}, |
|
|
{"password", required_argument, 0, opt_pass}, |
|
|
{"auto-reconnect", no_argument, 0, opt_auto_reconnect}, |
|
|
{"daemon", no_argument, 0, opt_daemon}, |
|
|
{"debug-level", required_argument, 0, opt_debug_level}, |
|
|
{"modem-device", required_argument, 0, opt_modem}, |
|
|
{"phone", required_argument, 0, opt_phone}, |
|
|
{"speed", required_argument, 0, opt_speed}, |
|
|
{"server-login", required_argument, 0, opt_server_login}, |
|
|
{"server-password", required_argument, 0, opt_server_pass}, |
|
|
{"pid-file", required_argument, 0, opt_pid_file}, |
|
|
{"rtscts", required_argument, 0, opt_rtscts}, |
|
|
{"init-str", required_argument, 0, opt_init_str}, |
|
|
{"dial-str", required_argument, 0, opt_dial_str}, |
|
208 |
{NULL, 0, NULL, 0} |
{NULL, 0, NULL, 0} |
209 |
}; |
}; |
210 |
|
|
211 |
void |
static void |
212 |
usage () |
usage () |
213 |
{ |
{ |
214 |
printf("Usage : %s [OPTIONS]\n |
printf("Usage : %s [OPTIONS]\n |
243 |
exit (0); |
exit (0); |
244 |
} |
} |
245 |
|
|
246 |
void |
static void |
247 |
version (void) |
version (void) |
248 |
{ |
{ |
249 |
printf ("%s (" PACKAGE ") v" VERSION "\n", program_name); |
printf ("%s (" PACKAGE ") v" VERSION "\n", program_name); |
251 |
} |
} |
252 |
|
|
253 |
static int |
static int |
254 |
set_opt_param (option_e opt_id) |
set_opt_param (int opt_id) |
255 |
{ |
{ |
256 |
int i; |
int i; |
257 |
|
|
258 |
for (i = 0; i < PARAM_MAX && param[i].opt_id != opt_id; i++) |
for (i = 0; i < PARAM_MAX && param[i].shortopt != opt_id; i++) |
259 |
; |
; |
260 |
if (i == PARAM_MAX) |
if (i == PARAM_MAX) |
261 |
return 1; |
return 1; |
262 |
if (param[i].opt_id == opt_id) |
if (param[i].shortopt == opt_id) |
263 |
{ |
{ |
264 |
/* We now we have a parameter */ |
/* We now we have a parameter */ |
265 |
assert ((param[i].type == boolean) || (optarg != NULL)); |
assert ((param[i].type == boolean) || (optarg != NULL)); |
281 |
return 0; |
return 0; |
282 |
} |
} |
283 |
|
|
284 |
|
static char* |
285 |
|
generate_short_options (void) |
286 |
|
{ |
287 |
|
char *tab, *p; |
288 |
|
int i; |
289 |
|
|
290 |
|
/* FIXME: should alloc less memory */ |
291 |
|
tab = (char*) malloc ((PARAM_MAX * 2) * sizeof(char) + |
292 |
|
strlen (short_options_head)); |
293 |
|
p = tab; |
294 |
|
strcpy (p, short_options_head); |
295 |
|
p += strlen (short_options_head); |
296 |
|
for (i = 0; i < PARAM_MAX; i++) |
297 |
|
{ |
298 |
|
if (param[i].shortopt != 0) |
299 |
|
{ |
300 |
|
*p++ = param[i].shortopt; |
301 |
|
if (param[i].type != boolean) /* we need an argument */ |
302 |
|
*p++ = ':'; |
303 |
|
} |
304 |
|
} |
305 |
|
*p = '\0'; |
306 |
|
return tab; |
307 |
|
} |
308 |
|
|
309 |
|
static struct option* |
310 |
|
generate_long_options (void) |
311 |
|
{ |
312 |
|
struct option* tab; |
313 |
|
struct option* p; |
314 |
|
int i; |
315 |
|
/* |
316 |
|
* Needed for long options without any corresponding short options |
317 |
|
* Start at 257 to be sure not to interfere with real short options. |
318 |
|
*/ |
319 |
|
unsigned last_free_id = 257; |
320 |
|
|
321 |
|
/* calcule head size */ |
322 |
|
for (i = 0; long_options_head[i].name != 0; i++) |
323 |
|
; |
324 |
|
|
325 |
|
/* FIXME: malloc smaller size */ |
326 |
|
tab = (struct option*) malloc ((PARAM_MAX + i) * sizeof (struct option)); |
327 |
|
p = tab; |
328 |
|
for (i = 0; long_options_head[i].name != 0; i++) |
329 |
|
memcpy (p++, &long_options_head[i], sizeof(struct option)); |
330 |
|
for (i = 0; i < PARAM_MAX; i++) |
331 |
|
{ |
332 |
|
if (param[i].longopt) |
333 |
|
{ |
334 |
|
p->name = param[i].longopt; |
335 |
|
if (param[i].type == boolean) |
336 |
|
p->has_arg = no_argument; |
337 |
|
else |
338 |
|
p->has_arg = required_argument; |
339 |
|
p->flag = NULL; |
340 |
|
p->val = (param[i].shortopt ? param[i].shortopt : last_free_id++); |
341 |
|
p++; |
342 |
|
} |
343 |
|
} |
344 |
|
|
345 |
|
p->name = NULL; |
346 |
|
p->has_arg = 0; |
347 |
|
p->flag = NULL; |
348 |
|
p->val = 0; |
349 |
|
|
350 |
|
return tab; |
351 |
|
} |
352 |
|
|
353 |
int |
int |
354 |
parse_command_line (argc, argv) |
parse_command_line (argc, argv) |
355 |
int argc; |
int argc; |
356 |
char **argv; |
char **argv; |
357 |
{ |
{ |
358 |
int c; |
int c; |
359 |
|
char *short_options; |
360 |
|
struct option *long_options; |
361 |
|
|
362 |
|
short_options = generate_short_options (); |
363 |
|
long_options = generate_long_options (); |
364 |
|
|
365 |
while ((c = getopt_long (argc, argv, short_options, long_options, |
while ((c = getopt_long (argc, argv, short_options, long_options, |
366 |
NULL)) != -1) |
NULL)) != -1) |
367 |
switch (c) |
switch (c) |
386 |
exit (1); |
exit (1); |
387 |
} |
} |
388 |
} |
} |
389 |
|
|
390 |
|
if (short_options) |
391 |
|
free (short_options); |
392 |
|
if (long_options) |
393 |
|
free (long_options); |
394 |
|
|
395 |
return 0; |
return 0; |
396 |
} |
} |
397 |
|
|