X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FIPStack%2Ftcp.c;h=dd94b92358e37bfc0c951875e3c1db88fc0fd08d;hb=3c85c92afe3f506a921447ef07963525d796137b;hp=7537a4b48fb4dab7611cd5d6600bbc48afe685e0;hpb=720eb9f95dd3272e980095cf24ee21fb9250adb3;p=tpg%2Facess2.git diff --git a/Modules/IPStack/tcp.c b/Modules/IPStack/tcp.c index 7537a4b4..dd94b923 100644 --- a/Modules/IPStack/tcp.c +++ b/Modules/IPStack/tcp.c @@ -64,14 +64,45 @@ void TCP_StartConnection(tTCPConnection *Conn) hdr->SourcePort = Conn->LocalPort; hdr->DestPort = Conn->RemotePort; - hdr->SequenceNumber = rand(); + Conn->NextSequenceSend = rand(); + hdr->SequenceNumber = Conn->NextSequenceSend; hdr->DataOffset = (sizeof(tTCPHeader)+3)/4; hdr->Flags = TCP_FLAG_SYN; + hdr->WindowSize = 0; // TODO + hdr->Checksum = 0; // TODO + hdr->UrgentPointer = 0; // SEND PACKET - // Send a TCP SYN to the target to open the connection + TCP_SendPacket( Conn, sizeof(tTCPHeader), &hdr ); return ; } +/** + * \brief Sends a packet from the specified connection, calculating the checksums + * \param Conn Connection + * \param Length Length of data + * \param Data Packet data + */ +void TCP_SendPacket( tTCPConnection *Conn, size_t Length, tTCPHeader *Data ) +{ + size_t buflen; + Uint32 *buf; + switch( Conn->Interface.Type ) + { + case 4: + buflen = 4 + 4 + 4 + ((Length+1)&1); + buf = malloc( buflen ); + buf[0] = Conn->Interface.IP4.Address.L; + buf[1] = Conn->RemoteIP.v4.L; + buf[2] = (htons(Length)<<16) | (6<<8) | 0; + Data->Checksum = 0; + memcpy( &buf[3], Data, buflen ); + Data->Checksum = IPv4_Checksum( buf, buflen ); + free(buf); + IPv4_SendPacket(Conn->Interface, Conn->RemoteIP.v4, IP4PROT_TCP, 0, sizeof(tTCPHeader), &hdr); + break; + } +} + /** * \fn void TCP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer) * \brief Handles a packet from the IP Layer