Fix confusing error message with -g and IPv6 addresses (fixes #58)

pull/67/head
David Schweikert 11 years ago
parent f65d335ecf
commit 3cf9a8a3cd

@ -1,3 +1,7 @@
UNRELEASED
* More tests added
* Fix confusing error message with -g and IPv6 addresses (#58, reported by Axel Beckert)
2014-03-08 David Schweikert <david@schweikert.ch> 2014-03-08 David Schweikert <david@schweikert.ch>
* Version 3.9 * Version 3.9
* Fix random output on socket error (reported by Aleksandrs Saveljevs, #56) * Fix random output on socket error (reported by Aleksandrs Saveljevs, #56)

@ -0,0 +1,10 @@
#!/usr/bin/perl -w
# regression testing for github issue #58
use Test::Command tests => 3;
my $cmd1 = Test::Command->new(cmd => "src/fping -a -g 2001:db8:120:4161::4/64");
$cmd1->exit_is_num(1);
$cmd1->stdout_is_eq("");
$cmd1->stderr_is_eq("Error: -g works only with IPv4 addresses\n");

@ -794,7 +794,7 @@ int main( int argc, char **argv )
} }
if( !num_hosts ) if( !num_hosts )
exit( 2 ); exit(1);
if(src_addr_present) { if(src_addr_present) {
socket_set_src_addr(s, src_addr); socket_set_src_addr(s, src_addr);
@ -880,10 +880,6 @@ void add_cidr(char *addr)
*addr_end = '\0'; *addr_end = '\0';
mask_str = addr_end + 1; mask_str = addr_end + 1;
mask = atoi(mask_str); mask = atoi(mask_str);
if(mask < 1 || mask > 30) {
fprintf(stderr, "Error: netmask must be between 1 and 30 (is: %s)\n", mask_str);
exit(2);
}
/* parse address (IPv4 only) */ /* parse address (IPv4 only) */
memset(&addr_hints, 0, sizeof(struct addrinfo)); memset(&addr_hints, 0, sizeof(struct addrinfo));
@ -892,14 +888,20 @@ void add_cidr(char *addr)
ret = getaddrinfo(addr, NULL, &addr_hints, &addr_res); ret = getaddrinfo(addr, NULL, &addr_hints, &addr_res);
if(ret) { if(ret) {
fprintf(stderr, "Error: can't parse address %s: %s\n", addr, gai_strerror(ret)); fprintf(stderr, "Error: can't parse address %s: %s\n", addr, gai_strerror(ret));
exit(2); exit(1);
} }
if(addr_res->ai_family != AF_INET) { if(addr_res->ai_family != AF_INET) {
fprintf(stderr, "Error: -g works only with IPv4 addresses\n"); fprintf(stderr, "Error: -g works only with IPv4 addresses\n");
exit(2); exit(1);
} }
net_addr = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr); net_addr = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr);
/* check mask */
if(mask < 1 || mask > 30) {
fprintf(stderr, "Error: netmask must be between 1 and 30 (is: %s)\n", mask_str);
exit(1);
}
/* convert mask integer from 1 to 32 to a bitmask */ /* convert mask integer from 1 to 32 to a bitmask */
bitmask = ((unsigned long) 0xFFFFFFFF) << (32-mask); bitmask = ((unsigned long) 0xFFFFFFFF) << (32-mask);
@ -934,11 +936,11 @@ void add_range(char *start, char *end)
ret = getaddrinfo(start, NULL, &addr_hints, &addr_res); ret = getaddrinfo(start, NULL, &addr_hints, &addr_res);
if(ret) { if(ret) {
fprintf(stderr, "Error: can't parse address %s: %s\n", start, gai_strerror(ret)); fprintf(stderr, "Error: can't parse address %s: %s\n", start, gai_strerror(ret));
exit(2); exit(1);
} }
if(addr_res->ai_family != AF_INET) { if(addr_res->ai_family != AF_INET) {
fprintf(stderr, "Error: -g works only with IPv4 addresses\n"); fprintf(stderr, "Error: -g works only with IPv4 addresses\n");
exit(2); exit(1);
} }
start_long = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr); start_long = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr);
@ -949,11 +951,11 @@ void add_range(char *start, char *end)
ret = getaddrinfo(end, NULL, &addr_hints, &addr_res); ret = getaddrinfo(end, NULL, &addr_hints, &addr_res);
if(ret) { if(ret) {
fprintf(stderr, "Error: can't parse address %s: %s\n", end, gai_strerror(ret)); fprintf(stderr, "Error: can't parse address %s: %s\n", end, gai_strerror(ret));
exit(2); exit(1);
} }
if(addr_res->ai_family != AF_INET) { if(addr_res->ai_family != AF_INET) {
fprintf(stderr, "Error: -g works only with IPv4 addresses\n"); fprintf(stderr, "Error: -g works only with IPv4 addresses\n");
exit(2); exit(1);
} }
end_long = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr); end_long = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr);

Loading…
Cancel
Save