/* It copies the amount of data contained into 'buffer' into 'tempbuf'. and it checks for buffer overflows. 
This function is useful in case the userland application does not know immediately all the data it has to write into the socket. This function provides a way to create the "stream" step by step, appending the new data to the old one. Then, when all the data has been bufferized, the application can call the  */
int sock_bufferize(const char *buffer, int size, char *tempbuf, int *offset, int totsize, int checkonly, char *errbuf, int errbuflen)
/* It copies the amount of data contained into 'buffer' into 'tempbuf'. and it checks for buffer overflows. 
This function is useful in case the userland application does not know immediately all the data it has to write into the socket. This function provides a way to create the "stream" step by step, appending the new data to the old one. Then, when all the data has been bufferized, the application can call the  */
int sock_bufferize(const char *buffer, int size, char *tempbuf, int *offset, int totsize, int checkonly, char *errbuf, int errbuflen)
{
	if ((*offset + size) > totsize)
	{
		if (errbuf)
			pcap_snprintf(errbuf, errbuflen, "Not enough space in the temporary send buffer.");
		return -1;
	}
	if (!checkonly)
		memcpy(tempbuf + (*offset), buffer, size);
	(*offset) += size;
	return 0;
}