/* Search the pool of buffers to find one that is free. If a buffer is found mark it as in use before returning its address.  */
static unsigned char * prvGetNextBuffer(void)
/* Search the pool of buffers to find one that is free. If a buffer is found mark it as in use before returning its address.  */
static unsigned char * prvGetNextBuffer(void)
{
long x;
unsigned char *pucReturn = NULL;
unsigned long ulAttempts = 0;
	while( pucReturn == NULL )
	{
		for( x = 0; x < ETH_NUM_BUFFERS; x++ )
		{
			if( ucBufferInUse[ x ] == pdFALSE )
			{
				ucBufferInUse[ x ] = pdTRUE;
				pucReturn = ( unsigned char * ) ETH_BUF( x );
				break;
			}
		}
		if( pucReturn == NULL )
		{
			ulAttempts++;
			if( ulAttempts >= emacBUFFER_WAIT_ATTEMPTS )
			{
				break;
			}
			vTaskDelay( emacBUFFER_WAIT_DELAY );
		}
	}
	return pucReturn;
}