hewei.it 4 years ago
parent
commit
a91aad6f5e
2 changed files with 4 additions and 3 deletions
  1. 1 1
      .gitattributes
  2. 3 2
      protocol/icmp.c

+ 1 - 1
.gitattributes

@@ -1 +1 @@
-utils/json.hpp linguist-vendored
+cpputil/json.hpp linguist-vendored

+ 3 - 2
protocol/icmp.c

@@ -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;
             }