|
|
@@ -8,6 +8,7 @@
|
|
|
#define PING_TIMEOUT 1000 // ms
|
|
|
int ping(const char* host, int cnt) {
|
|
|
static uint16_t seq = 0;
|
|
|
+ uint16_t pid16 = (uint16_t)getpid();
|
|
|
char ip[64] = {0};
|
|
|
uint32_t start_tick, end_tick;
|
|
|
uint64_t start_hrtime, end_hrtime;
|
|
|
@@ -58,7 +59,7 @@ int ping(const char* host, int cnt) {
|
|
|
|
|
|
icmp_req->icmp_type = ICMP_ECHO;
|
|
|
icmp_req->icmp_code = 0;
|
|
|
- icmp_req->icmp_id = getpid();
|
|
|
+ icmp_req->icmp_id = pid16;
|
|
|
for (int i = 0; i < sendbytes - sizeof(icmphdr_t); ++i) {
|
|
|
icmp_req->icmp_data[i] = i;
|
|
|
}
|
|
|
@@ -91,7 +92,7 @@ int ping(const char* host, int cnt) {
|
|
|
if (icmp_len == sendbytes) {
|
|
|
icmp_res = (icmp_t*)(recvbuf + ipheader->ihl*4);
|
|
|
if (icmp_res->icmp_type == ICMP_ECHOREPLY &&
|
|
|
- icmp_res->icmp_id == getpid() &&
|
|
|
+ icmp_res->icmp_id == pid16 &&
|
|
|
icmp_res->icmp_seq == seq) {
|
|
|
valid = true;
|
|
|
}
|