rohc_comp_set_random_cb

NAME
SYNOPSIS
DESCRIPTION
PARAMETERS
STRUCTURES
EXAMPLE
SEE ALSO

NAME

rohc_comp_set_random_cb − Set the user-defined callback for random numbers.

SYNOPSIS

#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

);

DESCRIPTION

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

PARAMETERS

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

STRUCTURES

EXAMPLE

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

SEE ALSO

rohc_comp.h(3), rohc_comp_random_cb_t(3)