X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FIPStack%2Ftcp.c;h=51f6ae4381a35c937051b9b09dccd590b35401a0;hb=4fc7efa62f7a33e0c8a499f5a175419c2d16c273;hp=374150368dc58de4c316532993cd80caff9abb95;hpb=94ecc5441605ad5151e625457531e7f90470db31;p=tpg%2Facess2.git diff --git a/Modules/IPStack/tcp.c b/Modules/IPStack/tcp.c index 37415036..51f6ae43 100644 --- a/Modules/IPStack/tcp.c +++ b/Modules/IPStack/tcp.c @@ -84,7 +84,7 @@ void TCP_SendPacket( tTCPConnection *Conn, size_t Length, tTCPHeader *Data ) buf[2] = (htons(Length)<<16) | (6<<8) | 0; Data->Checksum = 0; memcpy( &buf[3], Data, Length ); - Data->Checksum = IPv4_Checksum( buf, buflen ); + Data->Checksum = htons( IPv4_Checksum( buf, buflen ) ); free(buf); IPv4_SendPacket(Conn->Interface, Conn->RemoteIP.v4, IP4PROT_TCP, 0, Length, Data); break; @@ -231,7 +231,7 @@ void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffe srv->ConnectionsTail = conn; if(!srv->NewConnections) srv->NewConnections = conn; - SHORTLOCK(&srv->lConnections); + SHORTREL(&srv->lConnections); // Send the SYN ACK hdr->Flags |= TCP_FLAG_ACK; @@ -282,14 +282,16 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head tTCPStoredPacket *pkt; int dataLen; + // Syncronise sequence values if(Header->Flags & TCP_FLAG_SYN) { Connection->NextSequenceRcv = ntohl(Header->SequenceNumber) + 1; } + // Handle a server replying to our initial SYN if( Connection->State == TCP_ST_SYN_SENT ) { - if( (Header->Flags & (TCP_FLAG_SYN|TCP_FLAG_ACK)) == (TCP_FLAG_SYN|TCP_FLAG_ACK) ) { - + if( (Header->Flags & (TCP_FLAG_SYN|TCP_FLAG_ACK)) == (TCP_FLAG_SYN|TCP_FLAG_ACK) ) + { Header->DestPort = Header->SourcePort; Header->SourcePort = htons(Connection->LocalPort); Header->AcknowlegementNumber = htonl(Connection->NextSequenceRcv); @@ -303,6 +305,13 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head } } + // Handle a client confirming the connection + if( Connection->State == TCP_ST_HALFOPEN && (Header->Flags & TCP_FLAG_ACK) ) + { + Connection->State = TCP_ST_OPEN; + Log_Log("TCP", "Connection fully opened"); + } + // Get length of data dataLen = Length - (Header->DataOffset>>4)*4; Log_Log("TCP", "HandleConnectionPacket - dataLen = %i", dataLen); @@ -330,6 +339,7 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head } } + // Check for an empty packet if(dataLen == 0) { Log_Log("TCP", "Empty Packet"); return ;