forked from unpbook/unpv13e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproc_v6.c
49 lines (44 loc) · 1.27 KB
/
proc_v6.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "ping.h"
void
proc_v6(char *ptr, ssize_t len, struct msghdr *msg, struct timeval* tvrecv)
{
#ifdef IPV6
double rtt;
struct icmp6_hdr *icmp6;
struct timeval *tvsend;
struct cmsghdr *cmsg;
int hlim;
icmp6 = (struct icmp6_hdr *) ptr;
if (len < 8)
return; /* malformed packet */
if (icmp6->icmp6_type == ICMP6_ECHO_REPLY) {
if (icmp6->icmp6_id != pid)
return; /* not a response to our ECHO_REQUEST */
if (len < 16)
return; /* not enough data to use */
tvsend = (struct timeval *) (icmp6 + 1);
tv_sub(tvrecv, tvsend);
rtt = tvrecv->tv_sec * 1000.0 + tvrecv->tv_usec / 1000.0;
hlim = -1;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL; cmsg = CMSG_NXTHDR(msg, cmsg)) {
if (cmsg->cmsg_level == IPPROTO_IPV6 &&
cmsg->cmsg_type == IPV6_HOPLIMIT) {
hlim = *(u_int32_t *)CMSG_DATA(cmsg);
break;
}
}
printf("%d bytes from %s: seq=%u, hlim=",
len, Sock_ntop_host(pr->sarecv, pr->salen),
icmp6->icmp6_seq);
if (hlim == -1)
printf("???"); /* ancillary data missing */
else
printf("%d", hlim);
printf(", rtt=%.3f ms\n", rtt);
} else if (verbose) {
printf(" %d bytes from %s: type = %d, code = %d\n",
len, Sock_ntop_host(pr->sarecv, pr->salen),
icmp6->icmp6_type, icmp6->icmp6_code);
}
#endif /* IPV6 */
}