+ // TODO: Check for halfopen max
+
+ conn = calloc(1, sizeof(tTCPConnection));
+ conn->State = TCP_ST_HALFOPEN;
+ conn->LocalPort = srv->Port;
+ conn->RemotePort = ntohs(hdr->SourcePort);
+ conn->Interface = Interface;
+
+ 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;
+ // + (Length-(hdr->DataOffset>>4)*4);
+ conn->NextSequenceSend = rand();
+
+ // Create node
+ conn->Node.NumACLs = 1;
+ conn->Node.ACLs = &gVFS_ACL_EveryoneRW;
+ conn->Node.ImplInt = srv->NextID ++;
+ conn->Node.Read = TCP_Client_Read;
+ conn->Node.Write = TCP_Client_Write;
+ //conn->Node.Close = TCP_SrvConn_Close;
+
+ // 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
+ LOCK(&srv->lConnections);
+ if( !srv->Connections )
+ srv->Connections = conn;
+ else
+ srv->ConnectionsTail->Next = conn;
+ srv->ConnectionsTail = conn;
+ if(!srv->NewConnections)
+ srv->NewConnections = conn;
+ RELEASE(&srv->lConnections);
+
+ // 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, sizeof(tTCPHeader), hdr );
+
+ return ;