case 4: // Append IPv4 Pseudo Header
buflen = 4 + 4 + 4 + ((Length+1)&~1);
buf = malloc( buflen );
- buf[0] = Conn->Interface->IP4.Address.L;
+ buf[0] = ((tIPv4*)Conn->Interface->Address)->L;
buf[1] = Conn->RemoteIP.v4.L;
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;
srv->ConnectionsTail = conn;
if(!srv->NewConnections)
srv->NewConnections = conn;
- SHORTLOCK(&srv->lConnections);
+ SHORTREL(&srv->lConnections);
// Send the SYN ACK
hdr->Flags |= TCP_FLAG_ACK;
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);
}
}
+ // 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);
}
}
+ // Check for an empty packet
if(dataLen == 0) {
Log_Log("TCP", "Empty Packet");
return ;