--- bing.c.orig Fri Jan 19 19:28:53 2001 +++ bing.c Mon Aug 6 19:33:05 2012 @@ -170,6 +170,7 @@ static char rcsid[] = "$Id: bing.c,v 1.16.2.1 2001/01/ #include #include #include +#include #include #include #include @@ -755,7 +756,7 @@ int pr_pack(buf, cc, from) static int old_rrlen; static char old_rr[MAX_IPOPTLEN]; struct ip *ip; - struct timeval tv, *tp; + struct timeval tv, tv2, *tp; double triptime; int hlen, dupflag; @@ -798,9 +799,12 @@ int pr_pack(buf, cc, from) cc -= hlen; icp = (struct icmp *)(buf + hlen); if (icp->icmp_type == ICMP_ECHOREPLY) { + char *tmp; if (icp->icmp_id != ident) return -1; /* 'Twas not our ECHO */ - tp = (struct timeval *)ICMP_TO_DATA(icp); + tmp = (char *)ICMP_TO_DATA(icp); + memcpy(&tv2, tmp, sizeof(tv2)); + tp = &tv2; tvsub(&tv, tp); triptime = tv_usval(&tv); @@ -1231,17 +1235,30 @@ int main(argc, argv) struct hoststats *hs1, *hs2; int ntrans, nloops, bits; int i; - int ch, hold, recv_packlen, preload; + int ch, hold = 1, recv_packlen, preload; u_char *datap, *recv_packet; - char *target1, *target2, *malloc(); + char *target1, *target2; u_char ttl, loop; #ifdef IP_OPTIONS char rspace[3 + 4 * NROUTES + 1]; /* record route space */ #endif - hs1 = &hoststats1; hs2 = &hoststats2; + if (!(proto = getprotobyname("icmp"))) { + (void)fprintf(stderr, "bing: unknown protocol icmp.\n"); + exit(1); + } + if ((s = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) { + perror("bing: socket"); + exit(1); + } + /* Revoke privileges */ + if (seteuid(getuid()) == -1 || setuid(getuid()) == -1) { + err(1, "unable to drop permissions"); + exit(1); + } + preload = 0; datap = &outpack[8 + sizeof(struct timeval)]; while ((ch = getopt(argc, argv, "I:LRc:dDe:fh:i:l:nPp:rS:s:t:vVwz")) != EOF) @@ -1398,15 +1415,6 @@ int main(argc, argv) ident = getpid() & 0xFFFF; - if (!(proto = getprotobyname("icmp"))) { - (void)fprintf(stderr, "bing: unknown protocol icmp.\n"); - exit(1); - } - if ((s = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) { - perror("bing: socket"); - exit(1); - } - hold = 1; if (options & F_SO_DEBUG) (void)setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&hold, sizeof(hold));