diff options
author | Thomas Habets <thomas@habets.se> | 2014-05-29 16:48:23 +0100 |
---|---|---|
committer | Thomas Habets <thomas@habets.se> | 2014-05-29 16:48:23 +0100 |
commit | 3246791c659e3fc325cba42b6f938513a444697a (patch) | |
tree | 851e02d32876b1e534ba38c55496b7fbcc68454c | |
parent | b9f9015a741c1979953b4c8f5f959f95232a8bfe (diff) | |
download | arping-3246791c659e3fc325cba42b6f938513a444697a.tar.gz |
Always print beeps before other output.
-rwxr-xr-x | extra/testing.exp | 91 | ||||
-rw-r--r-- | src/arping.c | 52 |
2 files changed, 97 insertions, 46 deletions
diff --git a/extra/testing.exp b/extra/testing.exp index d4ffd75..4ddd796 100755 --- a/extra/testing.exp +++ b/extra/testing.exp @@ -92,6 +92,39 @@ rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/0.000 ms\r " expect eof +send_user -- "--------------- Ping IP Raw (-r) ------------------\n" +spawn $bin -c 2 -r $ip +expect -re "$mac\r +$mac\r +" +expect eof + +send_user -- "--------------- Ping IP Raw audio (-r -a) ------------------\n" +spawn $bin -c 2 -r -a $ip +expect -re "\a$mac\r +\a$mac\r +" +expect eof + +send_user -- "--------------- Ping IP Raw audio bad dest (-r -e) ------------------\n" +spawn $bin -c 2 -r -e $bad_ip +expect -re "\a\a" +expect eof + +send_user -- "--------------- Ping IP reverse raw (-R) ------------------\n" +spawn $bin -c 2 -R $ip +expect -re "$ip\r +$ip\r +" +expect eof + +send_user -- "--------------- Ping IP double raw (-R) ------------------\n" +spawn $bin -c 2 -R -r $ip +expect -re "$mac $ip\r +$mac $ip\r +" +expect eof + send_user -- "--------------- Ping IP max 2 (-C) ------------------\n" spawn $bin -C 2 -c 10 $ip expect -re "ARPING $ip\r @@ -120,9 +153,9 @@ expect eof send_user -- "--------------- Ping IP x 3 with audio (-a) ------------------\n" spawn $bin -c 3 -a $ip expect -re "ARPING $ip\r -60 bytes from $mac \\($ip\\): index=0 time=\[0-9.\]+ \[mu\]?sec\a\r -60 bytes from $mac \\($ip\\): index=1 time=\[0-9.\]+ \[mu\]?sec\a\r -60 bytes from $mac \\($ip\\): index=2 time=\[0-9.\]+ \[mu\]?sec\a\r +\a60 bytes from $mac \\($ip\\): index=0 time=\[0-9.\]+ \[mu\]?sec\r +\a60 bytes from $mac \\($ip\\): index=1 time=\[0-9.\]+ \[mu\]?sec\r +\a60 bytes from $mac \\($ip\\): index=2 time=\[0-9.\]+ \[mu\]?sec\r \r --- $ip statistics ---\r 3 packets transmitted, 3 packets received, 0% unanswered \\(0 extra\\)\r @@ -145,9 +178,9 @@ expect eof send_user -- "--------- Ping IP x 2 with inverted audio, bad IP (-e) ------------\n" spawn $bin -c 2 -e "$bad_ip" expect -re "ARPING $bad_ip\r -Timeout\r \aTimeout\r -\a\r +\aTimeout\r +\r --- $bad_ip statistics ---\r 2 packets transmitted, 0 packets received, 100% unanswered \\(0 extra\\)\r \r @@ -160,9 +193,8 @@ expect "!!\t 0% packet loss (0 extra)\r\n" expect eof send_user -- "--------- Ping IP x 2 with inverted audio, bad IP (-e -D) ------------\n" -# TODO: surely this should be \a.\a. ? spawn $bin -c 2 -e -i eth0 -D "$bad_ip" -expect "\a\a..\t100% packet loss (0 extra)\r\n" +expect "\a.\a.\t100% packet loss (0 extra)\r\n" expect eof send_user -- "--------------- Ping IP cisco style (-D) ------------------\n" @@ -172,7 +204,7 @@ expect eof send_user -- "--------------- Ping IP cisco style with audio (-D -a) -----------\n" spawn $bin -c 3 -D -a $ip -expect "!\a!\a!\a\t 0% packet loss (0 extra)\r\n" +expect "\a!\a!\a!\t 0% packet loss (0 extra)\r\n" expect eof send_user -- "--------------- Ping IP Targeted (-t) ------------------\n" @@ -207,6 +239,40 @@ rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/0.000 ms\r " expect eof +send_user -- "--------------- Ping MAC Raw (-r) ------------------\n" +spawn $bin -c 2 -r $mac -T $ip +expect -re "$ip\r +$ip\r +" +expect eof + +send_user -- "--------------- Ping MAC Raw audio (-r -a) ------------------\n" +spawn $bin -c 2 -a -r $mac -T $ip +expect -re "\a$ip\r +\a$ip\r +" +expect eof + +send_user -- "--------------- Ping MAC Raw audio bad dest (-r -e) ------------------\n" +spawn $bin -c 2 -r -e $bad_mac -T $ip +expect -re "\a\a" +expect eof + +send_user -- "--------------- Ping MAC reverse raw (-R) ------------------\n" +spawn $bin -c 2 -R $mac -T $ip +expect -re "$mac\r +$mac\r +" +expect eof + +send_user -- "--------------- Ping MAC double raw (-a -R) ------------------\n" +spawn $bin -c 2 -R -r $mac -T $ip +expect -re "$mac $ip\r +$mac $ip\r +" +expect eof + + send_user -- "--------------- Ping MAC max 2 (-C) ------------------\n" spawn $bin -A -C 2 -c 10 $mac -T $ip expect -re "ARPING $mac\r @@ -226,7 +292,7 @@ expect eof send_user -- "--------------- Ping MAC cisco style with audio (-D -a) -----------\n" spawn $bin -A -c 3 -D -a $mac -T $ip -expect "!\a!\a!\a\t 0% packet loss (0 extra)\r\n" +expect "\a!\a!\a!\t 0% packet loss (0 extra)\r\n" expect eof send_user -- "--------- Ping MAC x 2 with inverted audio (-e) ------------\n" @@ -244,9 +310,9 @@ expect eof send_user -- "--------- Ping MAC x 2 with inverted audio, bad dest (-e) ------------\n" spawn $bin -e -c 2 "$bad_mac" -T $ip expect -re "ARPING $bad_mac\r -Timeout\r \aTimeout\r -\a\r +\aTimeout\r +\r --- $bad_mac statistics ---\r 2 packets transmitted, 0 packets received, 100% unanswered \\(0 extra\\)\r \r @@ -259,7 +325,6 @@ expect "!!\t 0% packet loss (0 extra)\r\n" expect eof send_user -- "--------- Ping MAC x 2 with inverted audio, bad dest (-e -D) ------------\n" -# TODO: surely this should be \a.\a. ? spawn $bin -A -c 2 -e -i eth0 -D $bad_mac -T $ip -expect "\a\a..\t100% packet loss (0 extra)\r\n" +expect "\a.\a.\t100% packet loss (0 extra)\r\n" expect eof diff --git a/src/arping.c b/src/arping.c index c0780ff..b21897e 100644 --- a/src/arping.c +++ b/src/arping.c @@ -217,18 +217,6 @@ do_pcap_open_live(const char *device, int snaplen, } /** - * - */ -static void -count_missing_dots() -{ - while (numsent > numdots) { - putchar('.'); - numdots++; - } -} - -/** * Init libnet with specified ifname. Destroy if already inited. * If this function retries with different parameter it will preserve * the original error message and print that. @@ -738,10 +726,11 @@ pingip_recv(const char *unused, struct pcap_pkthdr *h, uint8_t *packet) update_stats(timespec2dbl(&arrival) - timespec2dbl(&lastpacketsent)); char buf[128]; + if (beep) { + printf("\a"); + } switch(display) { case DOT: - numdots++; - count_missing_dots(); putchar('!'); break; case NORMAL: @@ -769,10 +758,8 @@ pingip_recv(const char *unused, struct pcap_pkthdr *h, uint8_t *packet) default: fprintf(stderr, "arping: can't happen!\n"); } + fflush(stdout); - if (beep) { - printf("\a"); - } switch (display) { case QUIET: case DOT: @@ -845,14 +832,15 @@ pingmac_recv(const char *unused, struct pcap_pkthdr *h, uint8_t *packet) } update_stats(timespec2dbl(&arrival) - timespec2dbl(&lastpacketsent)); + if (beep) { + printf("\a"); + } char buf[128]; char buf2[128]; switch(display) { case QUIET: break; case DOT: - numdots++; - count_missing_dots(); putchar('!'); break; case NORMAL: @@ -877,9 +865,7 @@ pingmac_recv(const char *unused, struct pcap_pkthdr *h, uint8_t *packet) fprintf(stderr, "arping: can't-happen-bug\n"); sigint(0); } - if (beep) { - printf("\a"); - } + fflush(stdout); switch (display) { case QUIET: case DOT: @@ -983,10 +969,19 @@ ping_recv(pcap_t *pcap, uint32_t packetwait, pcap_handler func) r = select(fd + 1, &fds, NULL, NULL, &tv); switch (r) { case 0: /* timeout */ - if (display == NORMAL) { - if (numrecvd == old_received) { + if (numrecvd == old_received) { + if (reverse_beep) { + printf("\a"); + } + switch (display) { + case NORMAL: printf("Timeout\n"); + break; + case DOT: + printf("."); + break; } + fflush(stdout); } done = 1; break; @@ -1463,10 +1458,6 @@ int main(int argc, char **argv) r = numrecvd; ping_recv(pcap,packetwait, (pcap_handler)pingip_recv); - if (reverse_beep && !time_to_die && (r == numrecvd)) { - printf("\a"); - fflush(stdout); - } } } else { /* PINGMAC */ unsigned int c; @@ -1476,15 +1467,10 @@ int main(int argc, char **argv) r = numrecvd; ping_recv(pcap,packetwait, (pcap_handler)pingmac_recv); - if (reverse_beep && !time_to_die && (r == numrecvd)) { - printf("\a"); - fflush(stdout); - } } } if (display == DOT) { const float succ = 100.0 - 100.0 * (float)(numrecvd)/(float)numsent; - count_missing_dots(); printf("\t%3.0f%% packet loss (%d extra)\n", (succ < 0.0) ? 0.0 : succ, (succ < 0.0) ? (numrecvd - numsent) : 0); |