*/
void TCP_Initialise(void)
{
+ giTCP_NextOutPort += rand()%32;
IPStack_AddFile(&gTCP_ServerFile);
IPStack_AddFile(&gTCP_ClientFile);
IPv4_RegisterCallback(IP4PROT_TCP, TCP_GetPacket);
buf[2] = (htons(Length)<<16) | (6<<8) | 0;
Data->Checksum = 0;
memcpy( &buf[3], Data, Length );
- Data->Checksum = htons( IPv4_Checksum( buf, buflen ) );
+ if(Length & 1)
+ ((Uint8*)buf)[12+Length] = 0;
+ Data->Checksum = htons( IPv4_Checksum( (Uint16*)buf, buflen/2 ) );
free(buf);
IPv4_SendPacket(Conn->Interface, Conn->RemoteIP.v4, IP4PROT_TCP, 0, Length, Data);
break;
{
Log_Log("TCP", "TCP_GetPacket: SequenceNumber = 0x%x", ntohl(hdr->SequenceNumber));
Debug_HexDump(
- "[TCP ] Packet Data = ",
+ "TCP_GetPacket: Packet Data = ",
(Uint8*)hdr + (hdr->DataOffset >> 4)*4,
Length - (hdr->DataOffset >> 4)*4
);
// TODO: This should be moved out of the watcher thread,
// so that a single lost packet on one connection doesn't cause
// all connections on the interface to lag.
+ // - Meh, no real issue, as the cache shouldn't be that large
TCP_INT_UpdateRecievedFromFuture(Connection);
// ACK Packet
RingBuffer_Write( Connection->RecievedBuffer, Pkt->Data, Pkt->Length );
- #if USE_SELECT
VFS_MarkAvaliable(&Connection->Node, 1);
- #endif
Mutex_Release( &Connection->lRecievedPackets );
}
packet->SourcePort = htons(Connection->LocalPort);
packet->DestPort = htons(Connection->RemotePort);
packet->DataOffset = (sizeof(tTCPHeader)/4)*16;
- packet->WindowSize = TCP_WINDOW_SIZE;
+ packet->WindowSize = htons(TCP_WINDOW_SIZE);
packet->AcknowlegementNumber = htonl(Connection->NextSequenceRcv);
packet->SequenceNumber = htonl(Connection->NextSequenceSend);
memcpy(packet->Options, Data, Length);
Log_Debug("TCP", "Send sequence 0x%08x", Connection->NextSequenceSend);
- Debug_HexDump("[TCP ] TCP_INT_SendDataPacket: Data = ",
- Data, Length);
+ Debug_HexDump("TCP_INT_SendDataPacket: Data = ", Data, Length);
TCP_SendPacket( Connection, sizeof(tTCPHeader)+Length, packet );