rohc_comp_set_random_cb − Set the user-defined callback for random numbers.
#include <rohc/rohc_comp.h>
bool
rohc_comp_set_random_cb(
struct rohc_comp *const comp,
rohc_comp_random_cb_t callback,
void *const user_context
);
Set the user-defined callback for random numbers. The callback is called by the ROHC library every time a new random number is required. It currently happens only to initiate the Sequence Number (SN) of new IP-only, IP/UDP, or IP/UDP-Lite streams to a random value as defined by RFC 3095.
If no callback is defined, an internal one that always returns 0 will be defined for compatibility reasons.
do not use this function anymore, use rohc_comp_new2() instead
comp |
The ROHC compressor to set the random callback for |
callback
The random callback to set
user_context
Private data that will be given to the callback, may be used as a context by user
/**
* @brief Generate a random number
*
* @param comp The ROHC compressor
* @param user_context Should always be NULL
* @return A random number
*/
static int gen_random_num(const struct rohc_comp *const
comp,
void *const user_context)
{
return rand();
}
...
unsigned int seed;
/* initialize
the random generator */
seed = time(NULL);
srand(seed);
...
struct rohc_comp *compressor; /* the ROHC compressor */
...
compressor = rohc_comp_new2(ROHC_SMALL_CID,
ROHC_SMALL_CID_MAX,
gen_random_num, NULL);
if(compressor == NULL)
{
fprintf(stderr, "failed create the ROHC compressor0);
goto error;
}
...
// set the callback for random numbers
if(!rohc_comp_set_random_cb(compressor, gen_random_num,
NULL))
{
fprintf(stderr, "failed to set the callback for random
numbers0);
goto release_compressor;
}
...
rohc_comp_free(compressor);
rohc_comp.h(3), rohc_comp_random_cb_t(3)