//
#include <stdio.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <unistd.h>
#include <sys/time.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>//socket()
#include <arpa/inet.h>
//探测路由结构体:
struct Detect{
int seq; //当前报文序号
struct timeval * time; //记录时间
};
//计算时间差函数:
float timediff(struct timeval * recTime,struct timeval * nowTime){
struct timeval sub = *nowTime;
if ((sub.tv_usec -= recTime->tv_usec) < 0)
{
--(sub.tv_sec);
sub.tv_usec += 1000000;
}
sub.tv_sec -= recTime->tv_sec;
return sub.tv_sec * 1000.0 + sub.tv_usec / 1000.0; //转换单位为毫秒
}
//检查和函数:
unsigned short checkSum(unsigned short * icmp,int size){
unsigned int sum = 0;
while (size>1) {
sum = sum + *icmp;
icmp += 1; //这里不加2是因为short类型指针每次移动2字节
size = size - 2; //16位的方式求和
}
if (size == 1) {
sum = sum + *icmp;
}
//加完了如果有进位就,一定是第16位是1,让低位加1即可
sum = (sum >> 16) + (sum & 0xffff);
//只有有符号数有反码,无符号数没有反码的概念
return