tTCPConnection *conn;
Log("[TCP ] sizeof(tTCPHeader) = %i", sizeof(tTCPHeader));
+ Log("[TCP ] SourcePort = %i", ntohs(hdr->SourcePort));
Log("[TCP ] DestPort = %i", ntohs(hdr->DestPort));
- Log("[TCP ] DestPort = %i", ntohs(hdr->DestPort));
- Log("[TCP ] SequenceNumber = %i", ntohl(hdr->SequenceNumber));
- Log("[TCP ] AcknowlegementNumber = %i", ntohl(hdr->AcknowlegementNumber));
+ Log("[TCP ] SequenceNumber = 0x%x", ntohl(hdr->SequenceNumber));
+ Log("[TCP ] AcknowlegementNumber = 0x%x", ntohl(hdr->AcknowlegementNumber));
Log("[TCP ] DataOffset = %i", hdr->DataOffset >> 4);
Log("[TCP ] Flags = {");
Log("[TCP ] CWR = %B", !!(hdr->Flags & TCP_FLAG_CWR));
}
// Open a new connection (well, check that it's a SYN)
- //TODO
+ if(hdr->Flags != TCP_FLAG_SYN) {
+ Log("[TCP ] Packet is not a SYN");
+ continue;
+ }
+
+ conn = calloc(1, sizeof(tTCPConnection));
+ conn->State = TCP_ST_HALFOPEN;
+ conn->LocalPort = srv->Port;
+ conn->RemotePort = 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 );
+ 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
+ LOCK(&srv->lConnections);
+ conn->Next = srv->Connections;
+ srv->Connections = conn;
+ RELEASE(&srv->lConnections);
+
+ // Send the SYN ACK
+ Log("[TCP ] TODO: Sending SYN ACK");
+ hdr->Flags |= TCP_FLAG_ACK;
+ hdr->AcknowlegementNumber = hdr->SequenceNumber;
+ hdr->SequenceNumber = conn->NextSequenceSend;
+ hdr->DestPort = hdr->SourcePort;
+ hdr->SourcePort = srv->Port;
+ TCP_SendPacket( conn, sizeof(tTCPHeader), hdr );
break;
}
// === PROTOTYPES ===
void UDP_Initialise();
void UDP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer);
+void UDP_Unreachable(tInterface *Interface, int Code, void *Address, int Length, void *Buffer);
+void UDP_SendPacket(tUDPChannel *Channel, void *Data, size_t Length);
// --- Listening Server
tVFS_Node *UDP_Server_Init(tInterface *Interface);
char *UDP_Server_ReadDir(tVFS_Node *Node, int ID);
{
IPStack_AddFile(&gUDP_ServerFile);
IPStack_AddFile(&gUDP_ClientFile);
+ //IPv4_RegisterCallback(IP4PROT_UDP, UDP_GetPacket, UDP_Unreachable);
IPv4_RegisterCallback(IP4PROT_UDP, UDP_GetPacket);
}
chan = chan->Next)
{
if(chan->Interface != Interface) continue;
- //Log("[UDP ] Local (0x%04x) == Dest (0x%04x)", chan->LocalPort, ntohs(hdr->DestPort));
if(chan->LocalPort != ntohs(hdr->DestPort)) continue;
- //Log("[UDP ] Remote (0x%04x) == Source (0x%04x)", chan->RemotePort, ntohs(hdr->SourcePort));
if(chan->RemotePort != ntohs(hdr->SourcePort)) continue;
if(Interface->Type == 4) {
}
+/**
+ * \brief Handle an ICMP Unrechable Error
+ */
+void UDP_Unreachable(tInterface *Interface, int Code, void *Address, int Length, void *Buffer)
+{
+
+}
+
/**
* \brief Send a packet
* \param Channel Channel to send the packet from