Lab2_web / Mbed 2 deprecated webserverBlinky

Dependencies:   mbed

Fork of webserverBlinky by RealTimeCompLab2

Revision:
62:f192926e42f1
Parent:
61:b3c1a04efd0a
Parent:
60:2b770949c911
Child:
63:9253b0e1b7d8
diff -r b3c1a04efd0a -r f192926e42f1 main.cpp
--- a/main.cpp	Sun Jun 04 20:14:36 2017 +0000
+++ b/main.cpp	Sun Jun 04 20:32:27 2017 +0000
@@ -660,23 +660,25 @@
     headerCheckSum(); // calculate the IP header checksum
     
     // now we have to build a 12-byte TCP "pseudo-header" in front of the TCP header (containing some IP header values) in order to correctly calculate the TCP checksum
+    // this header  contains the most important parts of the IP header, i.e. source and destination address, protocol number and data length. 
     
-    char * pseudoHeader = s-12;
-    memcpy(tempHold, pseudoHeader, 12); // save the 12 bytes in the IP header where the TCP pseudo-Header must be built
+    char * pseudoHeader = s-12; // mark the start of the TCP pseudo-header
+    memcpy(tempHold, pseudoHeader, 12); // preserve the 12 bytes in the IP header where the TCP pseudo-Header must be built
     memcpy( pseudoHeader+0, srcAdr, 8); // IP source and destination addresses from IP header
     memset( pseudoHeader+8, 0, 1); // reserved, set to zero
     memset( pseudoHeader+9, protocolIP, 1); // protocol from IP header
-    memset( pseudoHeader+10, tcpSize>>8, 1); // size of TCP header
-    memset( pseudoHeader+11, tcpSize, 1); // size of TCP header
-    
+    memset( pseudoHeader+10, tcpSize>>8, 1); // size of IP data (TCP packet size)
+    memset( pseudoHeader+11, tcpSize, 1); // size of IP data (TCP packet size)
+
     // pseudo-header built, now we can calculate TCP checksum
     
     checksumtcp[0]=0;
     checksumtcp[1]=0;
-    int pseudoHeaderSum=dataCheckSum(s-12,tcpSize+12); // calculate the TCP checksum starting at the pseudo-header
+    int pseudoHeaderSum=dataCheckSum(pseudoHeader,tcpSize+12); // calculate the TCP checksum starting at the pseudo-header
     checksumtcp[0]=pseudoHeaderSum>>8;
     checksumtcp[1]=pseudoHeaderSum;
     memcpy( s-12, tempHold, 12); // restore the 12 bytes that the pseudo-header overwrote
+
     if (fastResponse==1) {
         fastResponse=0; // reset and skip 200 ms wait
     } else {