From 90892d5ec73faada6a90537122e15f7db596a1d5 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 24 Mar 2006 17:28:40 +0000 Subject: [PATCH] Allow specifying the local IP address via --from. --- src/util/prototester.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/util/prototester.c b/src/util/prototester.c index d5cd91fd..f3f12966 100644 --- a/src/util/prototester.c +++ b/src/util/prototester.c @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -419,6 +420,7 @@ static struct protocol_test * get_test_from_name ( const char *name ) { struct tester_options { char interface[IF_NAMESIZE]; + struct in_addr in_addr; }; static void usage ( char **argv ) { @@ -428,6 +430,7 @@ static void usage ( char **argv ) { "Global options:\n" " -h|--help Print this help message\n" " -i|--interface intf Use specified network interface\n" + " -f|--from ip-address Use specified local IP address\n" " -l|--list List available tests\n" "\n" "Use \"%s -h\" to view test-specific options\n", @@ -438,6 +441,7 @@ static int parse_options ( int argc, char **argv, struct tester_options *options ) { static struct option long_options[] = { { "interface", 1, NULL, 'i' }, + { "from", 1, NULL, 'f' }, { "list", 0, NULL, 'l' }, { "help", 0, NULL, 'h' }, { }, @@ -447,12 +451,13 @@ static int parse_options ( int argc, char **argv, /* Set default options */ memset ( options, 0, sizeof ( *options ) ); strncpy ( options->interface, "eth0", sizeof ( options->interface ) ); + inet_aton ( "192.168.0.2", &options->in_addr ); /* Parse command-line options */ while ( 1 ) { int option_index = 0; - c = getopt_long ( argc, argv, "+i:hl", long_options, + c = getopt_long ( argc, argv, "+i:f:hl", long_options, &option_index ); if ( c < 0 ) break; @@ -462,6 +467,13 @@ static int parse_options ( int argc, char **argv, strncpy ( options->interface, optarg, sizeof ( options->interface ) ); break; + case 'f': + if ( inet_aton ( optarg, &options->in_addr ) == 0 ) { + fprintf ( stderr, "Invalid IP address %s\n", + optarg ); + return -1; + } + break; case 'l': list_tests (); return -1; @@ -511,6 +523,7 @@ int main ( int argc, char **argv ) { /* Initialise the protocol stack */ init_tcpip(); + set_ipaddr ( options.in_addr ); /* Open the hijack device */ hijack_dev.name = options.interface;