Skip to content
Snippets Groups Projects
Commit f903bcea authored by John Hodge's avatar John Hodge
Browse files

IPStack - Fixed TCP checksuming

- Padded with zero, instead of Undefined
- Fixed ping to return the ping time, instead of the timestamp
parent 461ede93
No related merge requests found
...@@ -129,5 +129,5 @@ int ICMP_Ping(tInterface *Interface, tIPv4 Addr) ...@@ -129,5 +129,5 @@ int ICMP_Ping(tInterface *Interface, tIPv4 Addr)
if(now() > end) if(now() > end)
return -1; return -1;
return (int)ts; return (int)( now() - ts );
} }
...@@ -317,12 +317,15 @@ Uint16 IPv4_Checksum(const void *Buf, int Size) ...@@ -317,12 +317,15 @@ Uint16 IPv4_Checksum(const void *Buf, int Size)
const Uint16 *arr = Buf; const Uint16 *arr = Buf;
int i; int i;
Size = (Size + 1) >> 1; // 16-bit word count // Sum all whole words
for(i = 0; i < Size; i++ ) for(i = 0; i < Size/2; i++ )
{ {
Uint16 val = ntohs(arr[i]); Uint16 val = ntohs(arr[i]);
sum += val; sum += val;
} }
// Add the tail word
// if( i*2 != Size )
// sum += arr[i]&0xFF;
// Apply one's complement // Apply one's complement
while (sum >> 16) while (sum >> 16)
......
...@@ -90,6 +90,8 @@ void TCP_SendPacket( tTCPConnection *Conn, size_t Length, tTCPHeader *Data ) ...@@ -90,6 +90,8 @@ void TCP_SendPacket( tTCPConnection *Conn, size_t Length, tTCPHeader *Data )
buf[2] = (htons(Length)<<16) | (6<<8) | 0; buf[2] = (htons(Length)<<16) | (6<<8) | 0;
Data->Checksum = 0; Data->Checksum = 0;
memcpy( &buf[3], Data, Length ); memcpy( &buf[3], Data, Length );
if(Length & 1)
((Uint8*)buf)[12+Length] = 0;
Data->Checksum = htons( IPv4_Checksum( buf, buflen ) ); Data->Checksum = htons( IPv4_Checksum( buf, buflen ) );
free(buf); free(buf);
IPv4_SendPacket(Conn->Interface, Conn->RemoteIP.v4, IP4PROT_TCP, 0, Length, Data); IPv4_SendPacket(Conn->Interface, Conn->RemoteIP.v4, IP4PROT_TCP, 0, Length, Data);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment