Browse Source

Allow specifying the local IP address via --from.

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
90892d5ec7
1 changed files with 14 additions and 1 deletions
  1. 14
    1
      src/util/prototester.c

+ 14
- 1
src/util/prototester.c View File

11
 #include <getopt.h>
11
 #include <getopt.h>
12
 #include <assert.h>
12
 #include <assert.h>
13
 
13
 
14
+#include <gpxe/ip.h>
14
 #include <gpxe/tcp.h>
15
 #include <gpxe/tcp.h>
15
 #include <gpxe/hello.h>
16
 #include <gpxe/hello.h>
16
 
17
 
419
 
420
 
420
 struct tester_options {
421
 struct tester_options {
421
 	char interface[IF_NAMESIZE];
422
 	char interface[IF_NAMESIZE];
423
+	struct in_addr in_addr;
422
 };
424
 };
423
 
425
 
424
 static void usage ( char **argv ) {
426
 static void usage ( char **argv ) {
428
 		  "Global options:\n"
430
 		  "Global options:\n"
429
 		  "  -h|--help              Print this help message\n"
431
 		  "  -h|--help              Print this help message\n"
430
 		  "  -i|--interface intf    Use specified network interface\n"
432
 		  "  -i|--interface intf    Use specified network interface\n"
433
+		  "  -f|--from ip-address   Use specified local IP address\n"
431
 		  "  -l|--list              List available tests\n"
434
 		  "  -l|--list              List available tests\n"
432
 		  "\n"
435
 		  "\n"
433
 		  "Use \"%s <test> -h\" to view test-specific options\n",
436
 		  "Use \"%s <test> -h\" to view test-specific options\n",
438
 			   struct tester_options *options ) {
441
 			   struct tester_options *options ) {
439
 	static struct option long_options[] = {
442
 	static struct option long_options[] = {
440
 		{ "interface", 1, NULL, 'i' },
443
 		{ "interface", 1, NULL, 'i' },
444
+		{ "from", 1, NULL, 'f' },
441
 		{ "list", 0, NULL, 'l' },
445
 		{ "list", 0, NULL, 'l' },
442
 		{ "help", 0, NULL, 'h' },
446
 		{ "help", 0, NULL, 'h' },
443
 		{ },
447
 		{ },
447
 	/* Set default options */
451
 	/* Set default options */
448
 	memset ( options, 0, sizeof ( *options ) );
452
 	memset ( options, 0, sizeof ( *options ) );
449
 	strncpy ( options->interface, "eth0", sizeof ( options->interface ) );
453
 	strncpy ( options->interface, "eth0", sizeof ( options->interface ) );
454
+	inet_aton ( "192.168.0.2", &options->in_addr );
450
 
455
 
451
 	/* Parse command-line options */
456
 	/* Parse command-line options */
452
 	while ( 1 ) {
457
 	while ( 1 ) {
453
 		int option_index = 0;
458
 		int option_index = 0;
454
 		
459
 		
455
-		c = getopt_long ( argc, argv, "+i:hl", long_options,
460
+		c = getopt_long ( argc, argv, "+i:f:hl", long_options,
456
 				  &option_index );
461
 				  &option_index );
457
 		if ( c < 0 )
462
 		if ( c < 0 )
458
 			break;
463
 			break;
462
 			strncpy ( options->interface, optarg,
467
 			strncpy ( options->interface, optarg,
463
 				  sizeof ( options->interface ) );
468
 				  sizeof ( options->interface ) );
464
 			break;
469
 			break;
470
+		case 'f':
471
+			if ( inet_aton ( optarg, &options->in_addr ) == 0 ) {
472
+				fprintf ( stderr, "Invalid IP address %s\n",
473
+					  optarg );
474
+				return -1;
475
+			}
476
+			break;
465
 		case 'l':
477
 		case 'l':
466
 			list_tests ();
478
 			list_tests ();
467
 			return -1;
479
 			return -1;
511
 
523
 
512
 	/* Initialise the protocol stack */
524
 	/* Initialise the protocol stack */
513
 	init_tcpip();
525
 	init_tcpip();
526
+	set_ipaddr ( options.in_addr );
514
 
527
 
515
 	/* Open the hijack device */
528
 	/* Open the hijack device */
516
 	hijack_dev.name = options.interface;
529
 	hijack_dev.name = options.interface;

Loading…
Cancel
Save