Skip to content

Commit

Permalink
tools/nut-scanner/nut-scanner.c: handle_arg_cidr() rename "optarg" to…
Browse files Browse the repository at this point in the history
… "arg_addr" [networkupstools#2244]

Avoid warning about clash with a global variable.
Fallout of refactoring original code into a method.

Also make it `const` as we do not change the original value anyway.

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jul 8, 2024
1 parent e91412e commit c2f5221
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions tools/nut-scanner/nut-scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ static void * run_eaton_serial(void *arg)
return NULL;
}

static void handle_arg_cidr(char *optarg, int *auto_nets_ptr)
static void handle_arg_cidr(const char *arg_addr, int *auto_nets_ptr)
{
char *start_ip = NULL, *end_ip = NULL;
/* Scanning mode: IPv4, IPv6 or both */
Expand All @@ -434,7 +434,7 @@ static void handle_arg_cidr(char *optarg, int *auto_nets_ptr)
#endif

/* Is this a `-m auto<something_optional>` mode? */
if (!strncmp(optarg, "auto", 4)) {
if (!strncmp(arg_addr, "auto", 4)) {
/* TODO: Maybe split later, to allow separate
* `-m auto4/X` and `-m auto6/Y` requests?
*/
Expand All @@ -446,43 +446,43 @@ static void handle_arg_cidr(char *optarg, int *auto_nets_ptr)
/* Not very efficient to stack strcmp's, but
* also not a hot codepath to care much, either.
*/
if (!strcmp(optarg, "auto")) {
if (!strcmp(arg_addr, "auto")) {
auto_nets = 46;
} else if (!strcmp(optarg, "auto4")) {
} else if (!strcmp(arg_addr, "auto4")) {
auto_nets = 4;
} else if (!strcmp(optarg, "auto6")) {
} else if (!strcmp(arg_addr, "auto6")) {
auto_nets = 6;
} else if (!strncmp(optarg, "auto/", 5)) {
} else if (!strncmp(arg_addr, "auto/", 5)) {
auto_nets = 46;
masklen_hosts_limit = atoi(optarg + 5);
masklen_hosts_limit = atoi(arg_addr + 5);
if (masklen_hosts_limit < 0 || masklen_hosts_limit > 128) {
fatalx(EXIT_FAILURE,
"Invalid auto-net limit value: %s",
optarg);
arg_addr);
}
} else if (!strncmp(optarg, "auto4/", 6)) {
} else if (!strncmp(arg_addr, "auto4/", 6)) {
auto_nets = 4;
masklen_hosts_limit = atoi(optarg + 6);
masklen_hosts_limit = atoi(arg_addr + 6);
if (masklen_hosts_limit < 0 || masklen_hosts_limit > 32) {
fatalx(EXIT_FAILURE,
"Invalid auto-net limit value: %s",
optarg);
arg_addr);
}
} else if (!strncmp(optarg, "auto6/", 6)) {
} else if (!strncmp(arg_addr, "auto6/", 6)) {
auto_nets = 6;
masklen_hosts_limit = atoi(optarg + 6);
masklen_hosts_limit = atoi(arg_addr + 6);
if (masklen_hosts_limit < 0 || masklen_hosts_limit > 128) {
fatalx(EXIT_FAILURE,
"Invalid auto-net limit value: %s",
optarg);
arg_addr);
}
} else {
/* TODO: maybe fail right away?
* Or claim a simple auto46 mode? */
upsdebugx(0,
"Got a '-m auto*' CLI option with unsupported "
"keyword pattern; assuming a CIDR, "
"likely to fail: %s", optarg);
"likely to fail: %s", arg_addr);
}

/* Let the caller know, to allow for run-once support */
Expand All @@ -493,8 +493,8 @@ static void handle_arg_cidr(char *optarg, int *auto_nets_ptr)

if (auto_nets < 0) {
/* not a supported `-m auto*` pattern => is `-m cidr` */
upsdebugx(5, "Processing CIDR net/mask: %s", optarg);
nutscan_cidr_to_ip(optarg, &start_ip, &end_ip);
upsdebugx(5, "Processing CIDR net/mask: %s", arg_addr);
nutscan_cidr_to_ip(arg_addr, &start_ip, &end_ip);
upsdebugx(5, "Extracted IP address range from CIDR net/mask: %s => %s", start_ip, end_ip);

add_ip_range(start_ip, end_ip);
Expand Down

0 comments on commit c2f5221

Please sign in to comment.