- Log_Log("TCP", "TCP_GetPacket: Opening Connection");
- // Open a new connection (well, check that it's a SYN)
- if(hdr->Flags != TCP_FLAG_SYN) {
- Log_Log("TCP", "TCP_GetPacket: Packet is not a SYN");
- return ;
- }
-
- // TODO: Check for halfopen max
-
- tTCPConnection *conn = TCP_int_CreateConnection(Interface, TCP_ST_SYN_RCVD);
- conn->LocalPort = srv->Port;
- conn->RemotePort = ntohs(hdr->SourcePort);
-
- switch(Interface->Type)
- {
- case 4: conn->RemoteIP.v4 = *(tIPv4*)Address; break;
- case 6: conn->RemoteIP.v6 = *(tIPv6*)Address; break;
- }
-
- conn->NextSequenceRcv = ntohl( hdr->SequenceNumber ) + 1;
- conn->HighestSequenceRcvd = conn->NextSequenceRcv;
- conn->NextSequenceSend = rand();
-
- conn->Node.ImplInt = srv->NextID ++;
-
- // Hmm... Theoretically, this lock will never have to wait,
- // as the interface is locked to the watching thread, and this
- // runs in the watching thread. But, it's a good idea to have
- // it, just in case
- // Oh, wait, there is a case where a wildcard can be used
- // (srv->Interface == NULL) so having the lock is a good idea
- SHORTLOCK(&srv->lConnections);
- if( !srv->Connections )
- srv->Connections = conn;
- else
- srv->ConnectionsTail->Next = conn;
- srv->ConnectionsTail = conn;
- if(!srv->NewConnections)
- srv->NewConnections = conn;
- VFS_MarkAvaliable( &srv->Node, 1 );
- SHORTREL(&srv->lConnections);
- Semaphore_Signal(&srv->WaitingConnections, 1);
-
- // Send the SYN ACK
- hdr->Flags |= TCP_FLAG_ACK;
- hdr->AcknowlegementNumber = htonl(conn->NextSequenceRcv);
- hdr->SequenceNumber = htonl(conn->NextSequenceSend);
- hdr->DestPort = hdr->SourcePort;
- hdr->SourcePort = htons(srv->Port);
- hdr->DataOffset = (sizeof(tTCPHeader)/4) << 4;
- TCP_SendPacket( conn, hdr, 0, NULL );
- conn->NextSequenceSend ++;