RealtimeCompLab2
Dependencies: mbed
Fork of PPP-Blinky by
Diff: main.cpp
- Revision:
- 78:809c2631a5eb
- Parent:
- 77:abf92baebb42
- Child:
- 79:f0fc1c19a550
--- a/main.cpp Sat Jul 08 10:10:12 2017 +0000 +++ b/main.cpp Sun Jul 09 01:06:40 2017 +0000 @@ -601,7 +601,8 @@ int tcpDataSize = tcpSize - headerSizeTCP; // size of data block after TCP header unsigned int ack = (seqtcp[0]<<24)|(seqtcp[1]<<16)|(seqtcp[2]<<8)|(seqtcp[3]) + tcpDataSize; - unsigned int seq = (acktcp[0]<<24)|(acktcp[1]<<16)|(acktcp[2]<<8)|(acktcp[3]); + //unsigned int seq = (acktcp[0]<<24)|(acktcp[1]<<16)|(acktcp[2]<<8)|(acktcp[3]); + #define TCP_FLAG_ACK (1<<4) #define TCP_FLAG_SYN (1<<1) @@ -622,9 +623,11 @@ if ( tcpDataSize != 1 ) return; case TCP_FLAG_SYN: flagsOut = TCP_FLAG_SYN | TCP_FLAG_ACK; // something wants to connect - ack it + ppp.seq = ppp.seq + 12345; // create a new sequence number (normally random) ack++; // for SYN flag we have to increase sequence by 1 break; case TCP_FLAG_ACK | TCP_FLAG_PSH: + ppp.seq = (acktcp[0]<<24)|(acktcp[1]<<16)|(acktcp[2]<<8)|(acktcp[3]); // use their idea of our seq flagsOut = TCP_FLAG_ACK | TCP_FLAG_FIN; // for every push we answer once AND close the link fastResponse = 1; // we can respond fast to a push if ( strncmp(dataStart, "GET ", 4) == 0) { // do we see an http GET command @@ -643,6 +646,8 @@ default: return; // ignore remaining packets } + + unsigned int seq = ppp.seq; // The TCP flag handling is now done // Now we have to recalculate all the header sizes, swap IP address/port source and destination, and do the IP and TCP checksums @@ -705,9 +710,10 @@ } else { // normally, you wait 200 ms before sending a TCP packet // remove the wait to respond faster - wait(0.05); + // wait(0.2); } sendFrame(); // All done! Send the TCP packet + ppp.seq = ppp.seq + dataLen; // update our seq number } void dumpDataTCP()