mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #428 from sehraf/pr-fix-udp
fix TcpPacket::readPacket
This commit is contained in:
commit
019ed127bd
@ -186,19 +186,26 @@ int TcpPacket::readPacket(void *buf, int size)
|
||||
if (data)
|
||||
{
|
||||
free(data);
|
||||
data = NULL ;
|
||||
}
|
||||
datasize = size - TCP_PSEUDO_HDR_SIZE;
|
||||
|
||||
if(datasize == 0) // this happens!
|
||||
// this happens for control packets (e.g. syn/ack/fin)
|
||||
if(datasize == 0)
|
||||
{
|
||||
data = NULL ;
|
||||
return 0 ;
|
||||
// data is already NULL
|
||||
// just return packet size
|
||||
return size;
|
||||
}
|
||||
|
||||
data = (uint8 *) rs_malloc(datasize);
|
||||
|
||||
if(data == NULL)
|
||||
{
|
||||
// malloc failed!
|
||||
// return 0 to drop packet (will be retransmitted eventually)
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
/* now the data */
|
||||
memcpy(data, (void *) &(((uint8 *) buf)[20]), datasize);
|
||||
|
Loading…
Reference in New Issue
Block a user