tp.tv_sec = tvi.tv_sec; tp.tv_usec = tvi.tv_usec;
tp.tv_sec = ntohl(tvi.tv_sec); tp.tv_usec = ntohl(tvi.tv_usec);
pr_pack(buf, cc, from)	char *buf;	int cc;	struct sockaddr_in *from;{	register struct icmp *icp;	register in_addr_t l;	register u_int i, j;	register u_char *cp, *dp;	static int old_rrlen;	static char old_rr[MAX_IPOPTLEN];	struct ip *ip, *ip2;	struct timeval tv, tp;	char *pkttime;	quad_t triptime = 0;	int hlen, hlen2, dupflag;	(void)gettimeofday(&tv, (struct timezone *)NULL);	/* Check the IP header */	ip = (struct ip *)buf;	hlen = ip->ip_hl << 2;	if (cc < hlen + ICMP_MINLEN) {		if (options & F_VERBOSE)			warnx("packet too short (%d bytes) from %s", cc,			  inet_ntoa(*(struct in_addr *)&from->sin_addr.s_addr));		return;	}	/* Now the ICMP part */	cc -= hlen;	icp = (struct icmp *)(buf + hlen);	if (icp->icmp_type == ICMP_ECHOREPLY) {		if (icp->icmp_id != ident)			return;			/* 'Twas not our ECHO */		++nreceived;		if (timing) {			struct tvi tvi;#ifndef icmp_data			pkttime = (char *)&icp->icmp_ip;#else			pkttime = (char *)icp->icmp_data;#endif			memcpy(&tvi, pkttime, sizeof tvi);			tp.tv_sec = tvi.tv_sec;			tp.tv_usec = tvi.tv_usec;						timersub(&tv, &tp, &tv);			triptime = (tv.tv_sec * 1000000) + tv.tv_usec;			tsum += triptime;			if (triptime < tmin)				tmin = triptime;			if (triptime > tmax)				tmax = triptime;		}		if (TST(ntohs(icp->icmp_seq) % mx_dup_ck)) {			++nrepeats;			--nreceived;			dupflag = 1;		} else {			SET(ntohs(icp->icmp_seq) % mx_dup_ck);			dupflag = 0;		}		if (options & F_QUIET)			return;		if (options & F_FLOOD)			(void)write(STDOUT_FILENO, &BSPACE, 1);		else {			(void)printf("%d bytes from %s: icmp_seq=%u", cc,			   inet_ntoa(*(struct in_addr *)&from->sin_addr.s_addr),			   ntohs(icp->icmp_seq));			(void)printf(" ttl=%d", ip->ip_ttl);			if (timing)				(void)printf(" time=%d.%03d ms",				    (int)(triptime / 1000),				    (int)(triptime % 1000));			if (dupflag)				(void)printf(" (DUP!)");			/* check the data */			cp = (u_char*)&icp->icmp_data[sizeof(struct tvi)];			dp = &outpack[8 + sizeof(struct tvi)];			for (i = 8 + sizeof(struct tvi); i < datalen;			    ++i, ++cp, ++dp) {				if (*cp != *dp) {	(void)printf("\nwrong data byte #%d should be 0x%x but was 0x%x",	    i, *dp, *cp);					cp = (u_char*)&icp->icmp_data[0];					for (i = 8; i < datalen; ++i, ++cp) {						if ((i % 32) == 8)							(void)printf("\n\t");						(void)printf("%x ", *cp);					}					break;				}			}		}	} else {		/* We've got something other than an ECHOREPLY */		if (!(options & F_VERBOSE))			return;		ip2 = (struct ip *) (buf + hlen + sizeof (struct icmp));		hlen2 = ip2->ip_hl << 2; 		if (cc >= hlen2 + 8 && check_icmph((struct ip *)(icp +		    sizeof (struct icmp))) != 1)			return;		(void)printf("%d bytes from %s: ", cc,		    pr_addr(from->sin_addr.s_addr));		pr_icmph(icp);	}	/* Display any IP options */	cp = (u_char *)buf + sizeof(struct ip);	for (; hlen > (int)sizeof(struct ip); --hlen, ++cp)		switch (*cp) {		case IPOPT_EOL:			hlen = 0;			break;		case IPOPT_LSRR:			(void)printf("\nLSRR: ");			hlen -= 2;			j = *++cp;			++cp;			i = 0;			if (j > IPOPT_MINOFF) {				for (;;) {					l = *++cp;					l = (l<<8) + *++cp;					l = (l<<8) + *++cp;					l = (l<<8) + *++cp;					if (l == 0)						(void)printf("\t0.0.0.0");					else						(void)printf("\t%s",						    pr_addr(ntohl(l)));					hlen -= 4;					j -= 4;					i += 4;					if (j <= IPOPT_MINOFF)						break;					if (i >= MAX_IPOPTLEN) {						(void)printf("\t(truncated route)");						break;					}					(void)putchar('\n');				}			}			break;		case IPOPT_RR:			j = *++cp;		/* get length */			i = *++cp;		/* and pointer */			hlen -= 2;			if (i > j)				i = j;			i -= IPOPT_MINOFF;			if (i <= 0)				continue;			if (i == old_rrlen			    && cp == (u_char *)buf + sizeof(struct ip) + 2			    && !memcmp(cp, old_rr, i)			    && !(options & F_FLOOD)) {				(void)printf("\t(same route)");				i = ((i + 3) / 4) * 4;				hlen -= i;				cp += i;				break;			}			if (i < MAX_IPOPTLEN) {				old_rrlen = i;				memcpy(old_rr, cp, i);			} else				old_rrlen = 0;			(void)printf("\nRR: ");			j = 0;			for (;;) {				l = *++cp;				l = (l<<8) + *++cp;				l = (l<<8) + *++cp;				l = (l<<8) + *++cp;				if (l == 0)					(void)printf("\t0.0.0.0");				else					(void)printf("\t%s", pr_addr(ntohl(l)));				hlen -= 4;				i -= 4;				j += 4;				if (i <= 0)					break;				if (j >= MAX_IPOPTLEN) {					(void)printf("\t(truncated route)");					break;				}				(void)putchar('\n');			}			break;		case IPOPT_NOP:			(void)printf("\nNOP");			break;		default:			(void)printf("\nunknown option %x", *cp);			hlen = hlen + cp[1] - 1;			cp = cp + cp[1] - 1;			break;		}	if (!(options & F_FLOOD)) {		(void)putchar('\n');		(void)fflush(stdout);	}}