--- arping.c.orig Fri Jul 25 18:28:31 2003 +++ arping.c Fri Jul 25 18:28:33 2003 @@ -407,6 +407,7 @@ struct bpf_program bp; char must_be_pingip = 0; char have_eth_source = 0; + unsigned int n[6]; DEBUG(printf("main()\n")); @@ -481,8 +482,6 @@ break; case 's': // spoofed source MAC { - unsigned int n[6]; - if (sscanf(optarg, "%x:%x:%x:%x:%x:%x", &n[0], &n[1], @@ -504,8 +503,6 @@ case 't': must_be_pingip = 1; { - unsigned int n[6]; - if (sscanf(optarg, "%x:%x:%x:%x:%x:%x", &n[0], &n[1], @@ -545,40 +542,47 @@ exit(1); } - if (searchmac || (!dip && strchr(argv[optind], ':'))) { - unsigned int n[6]; - if (!dip) { - dip = ip_xmas; - } - - if (must_be_pingip) { - fprintf(stderr, "Specified switch can't be used in " - "MAC-ping mode\n"); - exit(1); - } - - if (sscanf(argv[optind], "%x:%x:%x:%x:%x:%x", - &n[0], - &n[1], - &n[2], - &n[3], - &n[4], - &n[5] - ) != 6) { - fprintf(stderr, "Illegal mac addr %s\n", argv[optind]); - return 1; - } - for (c = 0; c < 6; c++) { - eth_target[c] = n[c] & 0xff; - } + if (sscanf(argv[optind], "%x:%x:%x:%x:%x:%x", + &n[0], + &n[1], + &n[2], + &n[3], + &n[4], + &n[5] + ) == 6) { + searchmac = 1; + } else if(sscanf(argv[optind], "%2x%x.%2x%x.%2x%x", + &n[0], + &n[1], + &n[2], + &n[3], + &n[4], + &n[5] + ) == 6) { searchmac = 1; } else if (!dip) { - - if (-1 == (dip = libnet_name_resolve((u_char*)argv[optind], + if (ip_xmas) { + dip = ip_xmas; + } else if (-1 == (dip = libnet_name_resolve((u_char*)argv[optind], LIBNET_RESOLVE))) { fprintf(stderr, "arping: Can't resolve %s\n", argv[optind]); exit(1); + } + } else { + fprintf(stderr, "Illegal mac addr %s\n", argv[optind]); + return 1; + } + + if (searchmac && must_be_pingip) { + fprintf(stderr, "Specified switch can't be used in " + "MAC-ping mode\n"); + exit(1); + } + + if (searchmac) { + for (c = 0; c < 6; c++) { + eth_target[c] = n[c] & 0xff; } } if (finddup && maxcount == -1) {