aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/files.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-20 12:47:01 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-20 12:47:01 +0000
commit027271e5a94591da535187fa95d481a1fdbcd9dc (patch)
tree6cf6a1ed423a2099dfc0e694a6e2e04ab0213ca9 /networking/udhcp/files.c
parent0a0180cdc54c87ab53c48705cb2d49b8c19f460e (diff)
downloadbusybox-w32-027271e5a94591da535187fa95d481a1fdbcd9dc.tar.gz
busybox-w32-027271e5a94591da535187fa95d481a1fdbcd9dc.tar.bz2
busybox-w32-027271e5a94591da535187fa95d481a1fdbcd9dc.zip
udhcp: fix wrong order of args here: index_in_strings(opt, dhcp_option_strings);
code shrink while at it: function old new delta read_config 406 323 -83
Diffstat (limited to 'networking/udhcp/files.c')
-rw-r--r--networking/udhcp/files.c54
1 files changed, 23 insertions, 31 deletions
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index ca0c6cb20..6a93bd0e2 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -167,7 +167,7 @@ static int read_opt(const char *const_line, void *arg)
167 if (!opt) 167 if (!opt)
168 return 0; 168 return 0;
169 169
170 idx = index_in_strings(opt, dhcp_option_strings); /* NB: was strcasecmp! */ 170 idx = index_in_strings(dhcp_option_strings, opt); /* NB: was strcasecmp! */
171 if (idx < 0) 171 if (idx < 0)
172 return 0; 172 return 0;
173 option = &dhcp_options[idx]; 173 option = &dhcp_options[idx];
@@ -286,8 +286,6 @@ static const struct config_keyword keywords[] = {
286 {"start", read_ip, &(server_config.start_ip), "192.168.0.20"}, 286 {"start", read_ip, &(server_config.start_ip), "192.168.0.20"},
287 {"end", read_ip, &(server_config.end_ip), "192.168.0.254"}, 287 {"end", read_ip, &(server_config.end_ip), "192.168.0.254"},
288 {"interface", read_str, &(server_config.interface), "eth0"}, 288 {"interface", read_str, &(server_config.interface), "eth0"},
289 {"option", read_opt, &(server_config.options), ""},
290 {"opt", read_opt, &(server_config.options), ""},
291 /* Avoid "max_leases value not sane" warning by setting default 289 /* Avoid "max_leases value not sane" warning by setting default
292 * to default_end_ip - default_start_ip + 1: */ 290 * to default_end_ip - default_start_ip + 1: */
293 {"max_leases", read_u32, &(server_config.max_leases), "235"}, 291 {"max_leases", read_u32, &(server_config.max_leases), "235"},
@@ -299,13 +297,17 @@ static const struct config_keyword keywords[] = {
299 {"min_lease", read_u32, &(server_config.min_lease), "60"}, 297 {"min_lease", read_u32, &(server_config.min_lease), "60"},
300 {"lease_file", read_str, &(server_config.lease_file), LEASES_FILE}, 298 {"lease_file", read_str, &(server_config.lease_file), LEASES_FILE},
301 {"pidfile", read_str, &(server_config.pidfile), "/var/run/udhcpd.pid"}, 299 {"pidfile", read_str, &(server_config.pidfile), "/var/run/udhcpd.pid"},
302 {"notify_file", read_str, &(server_config.notify_file), ""},
303 {"siaddr", read_ip, &(server_config.siaddr), "0.0.0.0"}, 300 {"siaddr", read_ip, &(server_config.siaddr), "0.0.0.0"},
301 /* keywords with no defaults must be last! */
302 {"option", read_opt, &(server_config.options), ""},
303 {"opt", read_opt, &(server_config.options), ""},
304 {"notify_file", read_str, &(server_config.notify_file), ""},
304 {"sname", read_str, &(server_config.sname), ""}, 305 {"sname", read_str, &(server_config.sname), ""},
305 {"boot_file", read_str, &(server_config.boot_file), ""}, 306 {"boot_file", read_str, &(server_config.boot_file), ""},
306 {"static_lease", read_staticlease, &(server_config.static_leases), ""}, 307 {"static_lease", read_staticlease, &(server_config.static_leases), ""},
307 /* ADDME: static lease */ 308 /* ADDME: static lease */
308}; 309};
310enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 };
309 311
310 312
311/* 313/*
@@ -315,28 +317,23 @@ static const struct config_keyword keywords[] = {
315 */ 317 */
316#define READ_CONFIG_BUF_SIZE 80 318#define READ_CONFIG_BUF_SIZE 80
317 319
318int read_config(const char *file) 320void read_config(const char *file)
319{ 321{
320 FILE *in; 322 FILE *in;
321 char buffer[READ_CONFIG_BUF_SIZE], *token, *line; 323 char buffer[READ_CONFIG_BUF_SIZE], *token, *line;
322 int i, lm = 0; 324 int i, lineno;
323 325
324 for (i = 0; i < ARRAY_SIZE(keywords); i++) 326 for (i = 0; i < KWS_WITH_DEFAULTS; i++)
325 if (keywords[i].def[0]) 327 keywords[i].handler(keywords[i].def, keywords[i].var);
326 keywords[i].handler(keywords[i].def, keywords[i].var);
327 328
328 in = fopen_or_warn(file, "r"); 329 in = fopen_or_warn(file, "r");
329 if (!in) { 330 if (!in)
330 return 0; 331 return;
331 }
332 332
333 lineno = 0;
333 while (fgets(buffer, READ_CONFIG_BUF_SIZE, in)) { 334 while (fgets(buffer, READ_CONFIG_BUF_SIZE, in)) {
334 char debug_orig[READ_CONFIG_BUF_SIZE]; 335 lineno++;
335 336 /* *strchrnul(buffer, '\n') = '\0'; - trim() will do it */
336 lm++;
337 *strchrnul(buffer, '\n') = '\0';
338 if (ENABLE_FEATURE_UDHCP_DEBUG)
339 strcpy(debug_orig, buffer);
340 *strchrnul(buffer, '#') = '\0'; 337 *strchrnul(buffer, '#') = '\0';
341 338
342 token = strtok(buffer, " \t"); 339 token = strtok(buffer, " \t");
@@ -344,29 +341,24 @@ int read_config(const char *file)
344 line = strtok(NULL, ""); 341 line = strtok(NULL, "");
345 if (!line) continue; 342 if (!line) continue;
346 343
347 /* eat leading whitespace */ 344 trim(line); /* remove leading/trailing whitespace */
348 line = skip_whitespace(line);
349 /* eat trailing whitespace */
350 i = strlen(line) - 1;
351 while (i >= 0 && isspace(line[i]))
352 line[i--] = '\0';
353 345
354 for (i = 0; i < ARRAY_SIZE(keywords); i++) 346 for (i = 0; i < ARRAY_SIZE(keywords); i++) {
355 if (!strcasecmp(token, keywords[i].keyword)) 347 if (!strcasecmp(token, keywords[i].keyword)) {
356 if (!keywords[i].handler(line, keywords[i].var)) { 348 if (!keywords[i].handler(line, keywords[i].var)) {
357 bb_error_msg("cannot parse line %d of %s", lm, file); 349 bb_error_msg("can't parse line %d in %s at '%s'",
358 if (ENABLE_FEATURE_UDHCP_DEBUG) 350 lineno, file, line);
359 bb_error_msg("cannot parse '%s'", debug_orig);
360 /* reset back to the default value */ 351 /* reset back to the default value */
361 keywords[i].handler(keywords[i].def, keywords[i].var); 352 keywords[i].handler(keywords[i].def, keywords[i].var);
362 } 353 }
354 break;
355 }
356 }
363 } 357 }
364 fclose(in); 358 fclose(in);
365 359
366 server_config.start_ip = ntohl(server_config.start_ip); 360 server_config.start_ip = ntohl(server_config.start_ip);
367 server_config.end_ip = ntohl(server_config.end_ip); 361 server_config.end_ip = ntohl(server_config.end_ip);
368
369 return 1;
370} 362}
371 363
372 364