But please understand that I am providing premium content for free that takes hundreds of hours of time to research and write. The way of calculating checksums your server uses is not obvious and possibly not correct, since the bottom part of the data is not checksummed.The TCP/IP Guide - TCP Checksum Calculation and the TCP "Pseudo Header" UInt8* chkSummedEnd = ((UInt8*)sentData) + chkSummedLen įor (UInt16* p = (UInt16*)sentData p OPhdr.ChKSum = 0xffff - accumulator UInt32 chkSummedLen = sizeof( CommandKeyS )/2 Calculate checksum of the half of the data without using ChKSum. At this point all fields in sentData, except of OPhdr.ChKSum are properly initialized. You can remove get function of ChKSum field and before sending the data call this function to initialize the checksum: CalcChecksum( CommandKeyS* sentData ) I dont know C#, so replaced parts with C++ code hoping it's not too different. I assume ChkSum on the server is of type _int16 and initialized to 0. I assume you are sending to the server CommandKeyS structure and it's size is constant. Sent checksum should lead to calculated checksum become 0xffff. The server calculates the checksum only of the half of the received header and data. Please can somebody help with this calculation in C# ? Thanks for all your responses. I used code below, but when I send any msg from C# side to C++ side, it throws this error. I need to get right calculation for checksum in C#. Int const retDat = recvfrom(sock, (char*)&dataR, hdrR.Length, 0, (sockaddr*)(&from), &len) įor(unsigned _int16 *p = (unsigned _int16*)&mCKr p < (unsigned _int16*)&mCKr + ((retHdr+retDat)/2) p++) Int const retHdr = recvfrom(sock, (char*)&hdrR, sizeof(hdrR), 0, (sockaddr*)(&from), &len) struct OPtoLSs //struct for received data This is part of code where is receive and checksum calculation. Code below is for application writen in C++. I need your help with calculating checksum in C#.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |