summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMandar Gokhale <mandarg@mandarg.com>2016-12-07 23:20:20 -0500
committerTobias Klauser <tklauser@distanz.ch>2016-12-08 09:28:30 +0100
commitbf0df3ec1875df4b167aedd0fff25e7e56408b6b (patch)
tree7cfc7d52cedb96a9d87c9cea385c0c7ba8b358e9
parent7b71c2c487ec2eed2d8dcd22f621f6c913621312 (diff)
mausezahn: Add error handling for mismatched address families
Currently, mausezahn fails silently if, say the user has specified IPv6 addresses using `-A` and `-B` but has forgotten the -6 option. Add error handling for this and the (probably uncommon) reverse case, i.e. v4 src/dst specified, but used with the -6 option. Signed-off-by: Mandar Gokhale <mandarg@mandarg.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--staging/mausezahn.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/staging/mausezahn.c b/staging/mausezahn.c
index ec3bc0e..7acd6bc 100644
--- a/staging/mausezahn.c
+++ b/staging/mausezahn.c
@@ -671,6 +671,15 @@ int getopts (int argc, char *argv[])
tx.ip_src_rand = 1;
tx.ip_src_h = (u_int32_t) ( ((float) rand()/RAND_MAX)*0xE0000000); //this is 224.0.0.0
}
+ else if (ipv6_mode && (strstr(tx.ip_src_txt, ".") || strstr(tx.ip_dst_txt, "."))) {
+ fprintf(stderr, "You are using IPv6 mode but are providing IPv4 src/dst addresses.\n");
+ return 1;
+ }
+ else if (!ipv6_mode && (strstr(tx.ip_src_txt, ":") || strstr(tx.ip_dst_txt, ":"))) {
+ fprintf(stderr, "You are using IPv4 mode (the default) but are providing IPv6 src/dst addresses.\n");
+ fprintf(stderr, "Please use the -6 option for IPv6 mode.\n");
+ return 1;
+ }
else if (
(ipv6_mode && get_ip6_range_src(tx.ip_src_txt, l)) || // returns 1 when no range has been specified
(!ipv6_mode && get_ip_range_src(tx.ip_src_txt))
@@ -892,7 +901,7 @@ int main(int argc, char **argv)
if ( getopts(argc, argv) )
{
- (void) fprintf(stderr, " Invalid command line parameters!\n");
+ (void) fprintf(stderr, "Invalid command line parameters!\n");
help();
}