#include "rping.h" void proc_v4(char *ptr, struct timeval *tvrecv) { double rtt; struct libnet_ip_hdr *ip; struct libnet_icmp_hdr *icmp; struct timeval *tvsend; u_short len; int ihl; ip = (struct libnet_ip_hdr *)(ptr+link_offset); len = ntohs(ip->ip_len); ihl = (u_int)ip->ip_hl<<2; icmp = (struct libnet_icmp_hdr *)(ptr+link_offset+ihl); if (icmp->icmp_type == ICMP_ECHOREPLY) { tvsend = (struct timeval *)icmp->icmp_data; tv_sub(tvrecv,tvsend); rtt = tvrecv->tv_sec * 1000.0 + tvrecv->tv_usec / 1000.0; printf("%d bytes from %s: seq=%u, ttl=%u rtt=%.3f ms\n", len - ihl, libnet_host_lookup(dst_ip, 0), ntohs(icmp->icmp_seq), ip->ip_ttl, rtt); } }