From 2de653340c789c2ef4b442b146c3f3e53e306c31 Mon Sep 17 00:00:00 2001 From: Jon Schipp Date: Thu, 24 Jul 2014 18:01:43 +0000 Subject: mausezahn: bind to IP address in interactive mode Adds new option ``-l'' that can be used to set mausezahn's listen address to bind to an IP of choice. e.g. mausezahn -l 127.0.0.1 -x Signed-off-by: Jon Schipp Signed-off-by: Tobias Klauser --- mausezahn.8 | 3 +++ mausezahn.zsh | 1 + staging/cli.c | 2 +- staging/cli.h | 1 + staging/mausezahn.c | 9 +++++++-- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mausezahn.8 b/mausezahn.8 index 87959c6..1037737 100644 --- a/mausezahn.8 +++ b/mausezahn.8 @@ -73,6 +73,9 @@ Start mausezahn in interactive mode with a Cisco-like CLI. Use telnet to log into the local mausezahn instance. If no port has been specified, port 25542 is used by default. .PP +.SS -l +Specify the IP address mausezahn should bind to when in interactive mode, default: 0.0.0.0. +.PP .SS -v Verbose mode. Capital \-V is even more verbose. .PP diff --git a/mausezahn.zsh b/mausezahn.zsh index b6934db..57a56a1 100644 --- a/mausezahn.zsh +++ b/mausezahn.zsh @@ -42,6 +42,7 @@ _interfaces () { _arguments -s -S \ "-x[Interactive mode with telnet CLI, default port: 25542]" \ + "-l[Listen address in interactive mode, default: 0.0.0.0]" \ "(-6)-4[IPv4 mode (default)]" \ "(-4)-6[IPv6 mode]" \ "-c[Send packet count times, default:1, infinite:0]" \ diff --git a/staging/cli.c b/staging/cli.c index ad040a1..7d8e2ce 100644 --- a/staging/cli.c +++ b/staging/cli.c @@ -532,7 +532,7 @@ int cli() // Listen on port mz_port (default: 25542, towel day) memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); // TODO: specified interface + inet_aton(mz_listen_addr, &servaddr.sin_addr); servaddr.sin_port = htons(mz_port); bind(s, (struct sockaddr *)&servaddr, sizeof(servaddr)); diff --git a/staging/cli.h b/staging/cli.h index 5762de4..dd8e5e1 100644 --- a/staging/cli.h +++ b/staging/cli.h @@ -59,6 +59,7 @@ struct cli_def *gcli; char mz_username[32]; char mz_password[32]; char mz_enable[32]; +char mz_listen_addr[15]; int mz_port; struct mops *clipkt; // actual packet used by CLI thread diff --git a/staging/mausezahn.c b/staging/mausezahn.c index 759ac28..8b2c499 100644 --- a/staging/mausezahn.c +++ b/staging/mausezahn.c @@ -33,7 +33,7 @@ int verbose_level = 0; -static const char *short_options = "46hqvVSxra:A:b:B:c:d:E:f:F:p:P:t:T:M:Q:X:"; +static const char *short_options = "46hqvVSxra:A:b:B:c:d:E:f:F:l:p:P:t:T:M:Q:X:"; static void signal_handler(int number) { @@ -109,6 +109,7 @@ static void help(void) "Usage: mausezahn [options] [interface] ||\n" "Options:\n" " -x Interactive mode with telnet CLI, default port: 25542\n" + " -l Listen address to bind to when in interactive mode, default: 0.0.0.0\n" " -4 IPv4 mode (default)\n" " -6 IPv6 mode\n" " -c Send packet count times, default:1, infinite:0\n" @@ -208,8 +209,9 @@ int reset() fp2 = NULL; mz_port = 0; mz_rand = 0; + char mz_listen_addr[15] = "0.0.0.0"; mp_head = NULL; - + for (i=0;i