1 #include "ping.h"
2
3 void
proc_v6(char * ptr,ssize_t len,struct timeval * tvrecv)4 proc_v6(char *ptr, ssize_t len, struct timeval* tvrecv)
5 {
6 #ifdef IPV6
7 int hlen1, icmp6len;
8 double rtt;
9 struct ip6_hdr *ip6;
10 struct icmp6_hdr *icmp6;
11 struct timeval *tvsend;
12
13 ip6 = (struct ip6_hdr *) ptr; /* start of IPv6 header */
14 hlen1 = sizeof(struct ip6_hdr);
15 if (ip6->ip6_nxt != IPPROTO_ICMPV6)
16 err_quit("next header not IPPROTO_ICMPV6");
17
18 icmp6 = (struct icmp6_hdr *) (ptr + hlen1);
19 if ( (icmp6len = len - hlen1) < 8)
20 err_quit("icmp6len (%d) < 8", icmp6len);
21
22 if (icmp6->icmp6_type == ICMP6_ECHO_REPLY) {
23 if (icmp6->icmp6_id != pid)
24 return; /* not a response to our ECHO_REQUEST */
25 if (icmp6len < 16)
26 err_quit("icmp6len (%d) < 16", icmp6len);
27
28 tvsend = (struct timeval *) (icmp6 + 1);
29 tv_sub(tvrecv, tvsend);
30 rtt = tvrecv->tv_sec * 1000.0 + tvrecv->tv_usec / 1000.0;
31
32 printf("%d bytes from %s: seq=%u, hlim=%d, rtt=%.3f ms\n",
33 icmp6len, Sock_ntop_host(pr->sarecv, pr->salen),
34 icmp6->icmp6_seq, ip6->ip6_hlim, rtt);
35
36 } else if (verbose) {
37 printf(" %d bytes from %s: type = %d, code = %d\n",
38 icmp6len, Sock_ntop_host(pr->sarecv, pr->salen),
39 icmp6->icmp6_type, icmp6->icmp6_code);
40 }
41 #endif /* IPV6 */
42 }
43