--- bsdping.c.orig Thu Nov 26 10:08:06 1998 +++ ping.c Thu Nov 26 10:04:31 1998 @@ -69,6 +69,14 @@ * This program has to run SUID to ROOT to access the ICMP socket. */ +/* + * BSD patch by Harl to pick up ECHO_REPLY from firewalls that is otherwise + * not reported. + * + * Anti-copyright (1998) Steal what the fuck you want. + * + */ + #include #include #include @@ -149,6 +157,7 @@ char DOT = '.'; char *hostname; int ident; /* process id to identify our packets */ +static struct in_addr dest_addr_store; /* counters */ long npackets; /* max packets to transmit */ @@ -334,6 +343,8 @@ hostname = hnamebuf; } + dest_addr_store = to->sin_addr; + if (options & F_FLOOD && options & F_INTERVAL) errx(1, "-f and -i options are incompatible"); @@ -640,8 +651,18 @@ (void)gettimeofday(&tv, (struct timezone *)NULL); + /* Check the IP header */ ip = (struct ip *)buf; + + /* Check reply is from pinged host */ + if (memcmp(&dest_addr_store, &ip->ip_src.s_addr, sizeof(struct in_addr))) { + printf("Reply not from target. Source %s",inet_ntoa(*(struct in_addr *)&from->sin_addr.s_addr)); + (void)printf(" ttl=%d", ip->ip_ttl); + if (timing) + (void)printf(" time=%ld.%ld ms\n", triptime/10, triptime%10); + } + hlen = ip->ip_hl << 2; if (cc < hlen + ICMP_MINLEN) { if (options & F_VERBOSE) @@ -1280,3 +1301,5 @@ " [-w maxwait] host\n"); exit(1); } + +