Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of webserverBlinky by
Diff: PPP-Blinky/ppp-blinky.cpp
- Revision:
- 161:d59f778bc8ab
- Parent:
- 160:bd701ad564cb
- Child:
- 162:594729c0e5c1
diff -r bd701ad564cb -r d59f778bc8ab PPP-Blinky/ppp-blinky.cpp --- a/PPP-Blinky/ppp-blinky.cpp Sat Sep 02 17:35:29 2017 +0000 +++ b/PPP-Blinky/ppp-blinky.cpp Sat Sep 02 17:58:39 2017 +0000 @@ -486,15 +486,15 @@ } /// perform a 16-bit checksum. if the byte count is odd, stuff in an extra zero byte. -unsigned int dataCheckSum(unsigned char * ptr, int len, int restart) +unsigned int dataCheckSum(char * ptr, int len, int restart) { unsigned int i,hi,lo; unsigned char placeHolder; + if (restart) ppp.sum=0; if (len&1) { placeHolder = ptr[len]; ptr[len]=0; // if the byte count is odd, insert one extra zero byte is after the last real byte because we sum byte PAIRS } - if (restart) ppp.sum=0; i=0; while ( i<len ) { checkPc(); @@ -513,24 +513,10 @@ /// perform the checksum on an IP header void IpHeaderCheckSum() { - ppp.pkt.buf[4+10]=0; // zero the checsum in the IP header - ppp.pkt.buf[4+11]=0; // zero the checksum in the IP header - int len =(ppp.pkt.buf[4]&0xf)*4; // length of IP header in bytes - char * ptr = ppp.pkt.buf+4; // start of IP packet - int sum=0; - for (int i=0; i<len/2; i++) { - int hi = *ptr; - ptr++; - int lo = *ptr; - ptr++; - int val = ( lo & 0xff ) | ( (hi<<8) & 0xff00 ); - sum = sum + val; - checkPc(); - } - sum = sum + (sum>>16); - sum = ~sum; - ppp.pkt.buf[4+10]= (sum>>8); - ppp.pkt.buf[4+11]= (sum ); + ppp.ip->checksumR=0; // zero the checsum in the IP header + int len = 4 * ppp.ip->headerLength; // length of IP header in bytes + unsigned int sum = dataCheckSum(ppp.ipStart,len,1); + ppp.ip->checksumR = __REV16( sum ); // insert fresh checksum } /// swap the IP source and destination addresses @@ -659,7 +645,7 @@ icmpSum[0]=0; icmpSum[1]=0; // zero the checksum for recalculation int icmpLength = packetLength - headerSizeIP; // length of ICMP data portion - unsigned int sum = dataCheckSum( (unsigned char *)icmpType, icmpLength, 1); // this checksum on icmp data portion + unsigned int sum = dataCheckSum(icmpType, icmpLength, 1); // this checksum on icmp data portion icmpSum[0]=(sum>>8)&0xff; icmpSum[1]=(sum )&0xff; // new checksum for ICMP data portion @@ -1002,7 +988,7 @@ pseudoHeader.lengthR = __REV16( tcpSize ); // size of tcp packet dataCheckSum(pseudoHeader.start, 12, 1); // start with the TCP checksum of the pseudoheader ppp.tcp->checksumR = 0; // before TCP checksum calculations the checksum bytes must be set cleared - unsigned int pseudoHeaderSum=dataCheckSum((unsigned char *)ppp.tcpStart,tcpSize, 0); // continue the TCP checksum on the whole TCP packet + unsigned int pseudoHeaderSum=dataCheckSum(ppp.tcpStart,tcpSize, 0); // continue the TCP checksum on the whole TCP packet ppp.tcp->checksumR = __REV16( pseudoHeaderSum); // tcp checksum done, store it in the TCP header dumpHeaderIP(1); // dump outgoing IP header