1 #include	"ping.h"
2 
3 void
proc_v4(char * ptr,ssize_t len,struct timeval * tvrecv)4 proc_v4(char *ptr, ssize_t len, struct timeval *tvrecv)
5 {
6 	int				hlen1, icmplen;
7 	double			rtt;
8 	struct ip		*ip;
9 	struct icmp		*icmp;
10 	struct timeval	*tvsend;
11 
12 	ip = (struct ip *) ptr;		/* start of IP header */
13 	hlen1 = ip->ip_hl << 2;		/* length of IP header */
14 
15 	icmp = (struct icmp *) (ptr + hlen1);	/* start of ICMP header */
16 	if ( (icmplen = len - hlen1) < 8)
17 		err_quit("icmplen (%d) < 8", icmplen);
18 
19 	if (icmp->icmp_type == ICMP_ECHOREPLY) {
20 		if (icmp->icmp_id != pid)
21 			return;			/* not a response to our ECHO_REQUEST */
22 		if (icmplen < 16)
23 			err_quit("icmplen (%d) < 16", icmplen);
24 
25 		tvsend = (struct timeval *) icmp->icmp_data;
26 		tv_sub(tvrecv, tvsend);
27 		rtt = tvrecv->tv_sec * 1000.0 + tvrecv->tv_usec / 1000.0;
28 
29 		printf("%d bytes from %s: seq=%u, ttl=%d, rtt=%.3f ms\n",
30 				icmplen, Sock_ntop_host(pr->sarecv, pr->salen),
31 				icmp->icmp_seq, ip->ip_ttl, rtt);
32 
33 	} else if (verbose) {
34 		printf("  %d bytes from %s: type = %d, code = %d\n",
35 				icmplen, Sock_ntop_host(pr->sarecv, pr->salen),
36 				icmp->icmp_type, icmp->icmp_code);
37 	}
38 }
39