瀏覽代碼

Allow specifying the local IP address via --from.

tags/v0.9.3
Michael Brown 18 年之前
父節點
當前提交
90892d5ec7
共有 1 個檔案被更改,包括 14 行新增1 行删除
  1. 14
    1
      src/util/prototester.c

+ 14
- 1
src/util/prototester.c 查看文件

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

Loading…
取消
儲存