diff options
author | Thomas Habets <thomas@habets.se> | 2019-12-19 18:55:03 +0000 |
---|---|---|
committer | Thomas Habets <thomas@habets.se> | 2019-12-19 18:55:03 +0000 |
commit | 0ec71e7bf46ad82124ba4b1f95b3609b28135498 (patch) | |
tree | 4494af05c916bcbcc134e2d0dbbe43ff76fb7e59 | |
parent | 9e292067f7501cc5001e2c659c4cd88e79cceec2 (diff) | |
download | arping-0ec71e7bf46ad82124ba4b1f95b3609b28135498.tar.gz |
More verbosity in pingmac, and check icmp code
-rw-r--r-- | src/arping.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/arping.c b/src/arping.c index 5973d36..d1855a1 100644 --- a/src/arping.c +++ b/src/arping.c @@ -1347,6 +1347,10 @@ pingmac_recv(const char* unused, struct pcap_pkthdr *h, uint8_t *packet) return; } + if (verbose > 3) { + printf("arping: ... right dst mac\n"); + } + // Source MAC must match, if set. if (memcmp(dstmac, ethxmas, ETH_ALEN)) { if (memcmp(pkt_srcmac, dstmac, ETH_ALEN)) { @@ -1354,6 +1358,10 @@ pingmac_recv(const char* unused, struct pcap_pkthdr *h, uint8_t *packet) } } + if (verbose > 3) { + printf("arping: ... right src mac\n"); + } + // IPv4 Address must be me (maybe). if (addr_must_be_same) { uint32_t tmp; @@ -1363,11 +1371,37 @@ pingmac_recv(const char* unused, struct pcap_pkthdr *h, uint8_t *packet) } } - // Must be ICMP echo reply. + if (verbose > 3) { + printf("arping: ... src IP acceptable\n"); + } + + // Must be ICMP echo reply type. if (htons(hicmp->icmp_type) != ICMP_ECHOREPLY) { return; } + if (verbose > 3) { + printf("arping: ... is echo reply type\n"); + } + + // Must be ICMP echo reply code 0. + if (htons(hicmp->icmp_code) != 0) { + return; + } + + if (verbose > 3) { + printf("arping: ... is echo reply code\n"); + } + + const char* payload = (char*)hicmp + LIBNET_ICMPV4_ECHO_H; + const ssize_t payload_size = h->len - (payload - (char*)packet); + if (payload_size < 0) { + return; + } + if (verbose > 3) { + printf("arping: ... payload size: %d\n", payload_size); + } + update_stats(timespec2dbl(&arrival) - timespec2dbl(&lastpacketsent)); if (beep) { printf("\a"); |