diff options
author | Arisotura <thetotalworm@gmail.com> | 2019-03-09 02:04:01 +0100 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2019-03-09 02:04:01 +0100 |
commit | 7d2b3bbf76255820e2fe8464429e25c2cc92e6f9 (patch) | |
tree | e585bd71b65c06944177c98c5bf8a400235afb15 /src/libui_sdl/LAN_Socket.cpp | |
parent | cde1963e63c72814ca971f2bcbda8379667f472c (diff) |
fix TCP checksum for odd lengths
Diffstat (limited to 'src/libui_sdl/LAN_Socket.cpp')
-rw-r--r-- | src/libui_sdl/LAN_Socket.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/libui_sdl/LAN_Socket.cpp b/src/libui_sdl/LAN_Socket.cpp index 1aea648..c3ad991 100644 --- a/src/libui_sdl/LAN_Socket.cpp +++ b/src/libui_sdl/LAN_Socket.cpp @@ -176,8 +176,10 @@ void FinishTCPFrame(u8* data, int len) tmp += ntohs(*(u16*)&ipheader[18]); tmp += ntohs(0x0600); tmp += tcplen; - for (u8* i = tcpheader; i < &tcpheader[tcplen]; i += 2) + for (u8* i = tcpheader; i < &tcpheader[tcplen-1]; i += 2) tmp += ntohs(*(u16*)i); + if (tcplen & 1) + tmp += ntohs((u_short)tcpheader[tcplen-1]); while (tmp >> 16) tmp = (tmp & 0xFFFF) + (tmp >> 16); tmp ^= 0xFFFF; @@ -526,7 +528,7 @@ void TCP_SYNACK(TCPSocket* sock, u8* data, int len) *out++ = 0x08; u32 framelen = (u32)(out - &resp[0]); - if (framelen & 1) { *out++ = 0; framelen++; } + //if (framelen & 1) { *out++ = 0; framelen++; } FinishTCPFrame(resp, framelen); // TODO: if there is already a packet queued, this will overwrite it @@ -577,7 +579,7 @@ void TCP_ACK(TCPSocket* sock, u8* data, int len) *(u16*)out = 0; out += 2; // urgent pointer u32 framelen = (u32)(out - &resp[0]); - if (framelen & 1) { *out++ = 0; framelen++; } + //if (framelen & 1) { *out++ = 0; framelen++; } FinishTCPFrame(resp, framelen); // TODO: if there is already a packet queued, this will overwrite it @@ -629,7 +631,6 @@ void TCP_BuildIncomingFrame(TCPSocket* sock, u8* data, int len) memcpy(out, data, len); out += len; u32 framelen = (u32)(out - &resp[0]); - if (framelen & 1) { *out++ = 0; framelen++; } FinishTCPFrame(resp, framelen); // TODO: if there is already a packet queued, this will overwrite it |