Question: i have found out that the cecksumcomputation over the payload is wrong / / Compute checksum over payload data uint 8 _ t byte =
i have found out that the cecksumcomputation over the payload is wrong
Compute checksum over payload data
uintt byte ;
for sizet i ; i sz; i
Extract each byte of the payload data and XOR it with the checksum
byte bufferi;
Convert byte to network byte order before XOR
checksum byte ;
checksum byte ;
i have also tried this method
for sizet i ; i sz; i
XOR each byte of the payload data with the checksum
checksum bufferi;
both wrong, black box server gets different checksum when ther is data but, it gets equal checkum when there is no data so how do you compute the checksum over the data aka payload?
my entire checksum computation is within this function
int dsenddata DPeer peer, char buffer, sizet sz
Check if peer or buffer is NULL
if peer NULL buffer NULL
return ; Return negative value for error
Calculate the total size of the packet header data
sizet packetsize sizeofDHeader sz;
Check if the packet size exceeds the maximum allowed size
if packetsize
fprintfstderr "Error: Packet size exceeds maximum allowed size
;
return ; Return negative value for error
Create a DHeader and populate its fields
DHeader header;
header.flags FLAGDATA;
header.size packetsize;
Compute the checksum
uintt checksum ;
Compute checksum over flags and size fields
checksum header.flags; checksum for flag field
checksum header.size ; Compute checksum for the upper bits of size
checksum header.size & xFFFF; Compute checksum for the lower bits of size
Compute checksum over payload data
uintt byte ;
for sizet i ; i sz; i
Extract each byte of the payload data and XOR it with the checksum
byte bufferi;
Convert byte to network byte order before XOR
checksum byte ;
checksum byte ;
Add padding byte if the payload size is odd
if sz
printfodd data";
checksum x;
convert all fields to network byte order before sending the packet
header.flags htonsheaderflags;
header.size htonlheadersize;
header.checksum htonschecksum; Convert checksum to network byte order
char packet;
memcpypacket &header, sizeofDHeader;
memcpypacket sizeofDHeader buffer, sz;
Send the packet header to the peer using sendto
printfsending header
;
ssizet bytessent sendtopeersocket, packet, packetsize,
struct sockaddr&peeraddr, sizeofstruct sockaddrin;
if bytessent
perrorError sending header";
return ; Return negative value for error
Receive and validate the ACK packet
DHeader ackpacket;
printfwaiting for ack
;
ssizet ackbytesreceived recvpeersocket, void&ackpacket, sizeofDHeader;
if ackbytesreceived
perrorError receiving ACK packet";
return ; Return negative value for error
Validate the ACK packet
uintt ackflags ntohsackpacket.flags;
Check if received packet is an ACK and sequence number matches
if ackflags & FLAGACK && ackflags & SEQNO peernextseqno
Valid ACK received
peernextseqno peernextseqno ;
return bytessent; Success: return number of bytes sent
else
dsenddatapeer buffer, sz;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
