]> git.seodisparate.com - UDPConnection/commitdiff
Fix prepare_pkt function
authorStephen Seo <seo.disparate@gmail.com>
Tue, 12 Mar 2019 05:28:28 +0000 (14:28 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 12 Mar 2019 05:28:28 +0000 (14:28 +0900)
src/UDPConnection.c
src/UDPConnection.h

index fecacda8a1a176f6fd7ffd386066e50316203c4e..969e4c3afe4edb187ed86d444e69fd9b35da0bb1 100644 (file)
@@ -940,11 +940,11 @@ void UDPC_INTERNAL_update_send(void *userData, uint32_t addr, char *data)
             UDPC_INTERNAL_prepare_pkt(
                 data,
                 us->ctx->protocolID,
-                UDPC_ID_CONNECT,
+                0,
                 0,
                 0xFFFFFFFF,
                 NULL,
-                0);
+                0x8);
 
             struct sockaddr_in destinationInfo;
             destinationInfo.sin_family = AF_INET;
@@ -976,11 +976,11 @@ void UDPC_INTERNAL_update_send(void *userData, uint32_t addr, char *data)
             UDPC_INTERNAL_prepare_pkt(
                 data,
                 us->ctx->protocolID,
-                UDPC_ID_CONNECT | cd->id,
+                cd->id,
                 cd->rseq,
                 cd->ack,
                 &cd->lseq,
-                0);
+                0x8);
 
             struct sockaddr_in destinationInfo;
             destinationInfo.sin_family = AF_INET;
@@ -1362,21 +1362,13 @@ void UDPC_INTERNAL_prepare_pkt(
 
     temp = htonl(protocolID);
     memcpy(d, &temp, 4);
-    if((flags & 0x4) == 0)
-    {
-        temp = htonl(conID | UDPC_ID_NO_REC_CHK);
-        memcpy(&d[4], &temp, 4);
-    }
-    else if((flags & 0x1) != 0)
-    {
-        temp = htonl(conID | UDPC_ID_PING);
-        memcpy(&d[4], &temp, 4);
-    }
-    else
-    {
-        temp = htonl(conID | ((flags & 0x2) != 0 ? UDPC_ID_RESENDING : 0));
-        memcpy(&d[4], &temp, 4);
-    }
+
+    temp = htonl(conID
+        | ((flags & 0x1) != 0 ? UDPC_ID_PING : 0)
+        | ((flags & 0x2) != 0 ? UDPC_ID_RESENDING : 0)
+        | ((flags & 0x4) == 0 ? UDPC_ID_NO_REC_CHK : 0)
+        | ((flags & 0x8) != 0 ? UDPC_ID_CONNECT : 0));
+    memcpy(&d[4], &temp, 4);
 
     if(seqID)
     {
index 466d77d09391f82e0d4e7882f724a9c9fa7561cf..eafb0667f0263142c100003b092bd0148c4bdc16 100644 (file)
@@ -286,6 +286,7 @@ int UDPC_INTERNAL_threadfn(void *context);
  * 0x1 - is ping
  * 0x2 - is resending
  * 0x4 - is checked received packet
+ * 0x8 - is init connection packet
  */
 void UDPC_INTERNAL_prepare_pkt(
     void *data,