Merge pull request #428 from sehraf/pr-fix-udp

fix TcpPacket::readPacket
This commit is contained in:
Cyril Soler 2016-06-28 12:37:04 -04:00 committed by GitHub
commit 019ed127bd

View File

@ -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);