Merge pull request #374 from mrdeep1/fix_prng_init

net.c: Start new coap_context with a random message identifier
This commit is contained in:
obgm authored and GitHub committed 2019-07-09 10:38:49 +02:00
commit cfe83f19dc
2 files changed
+14 -7

No files matched your search

+8
View File
@@ -47,6 +47,10 @@ COAP_STATIC_INLINE coap_time_t coap_ticks_to_rt(coap_tick_t t) {
return t / COAP_TICKS_PER_SECOND;
}
COAP_STATIC_INLINE uint64_t coap_ticks_to_rt_us(coap_tick_t t) {
return (uint64_t)t * 1000000 / COAP_TICKS_PER_SECOND;
}
#elif defined(WITH_CONTIKI)
#include "clock.h"
@@ -75,6 +79,10 @@ COAP_STATIC_INLINE coap_time_t coap_ticks_to_rt(coap_tick_t t) {
return t / COAP_TICKS_PER_SECOND;
}
COAP_STATIC_INLINE uint64_t coap_ticks_to_rt_us(coap_tick_t t) {
return (uint64_t)t * 1000000 / COAP_TICKS_PER_SECOND;
}
#else
#include <stdint.h>
+6 -7
View File
@@ -2358,6 +2358,8 @@ coap_can_exit(coap_context_t *context) {
static int coap_started = 0;
void coap_startup(void) {
coap_tick_t now;
uint64_t us;
if (coap_started)
return;
coap_started = 1;
@@ -2367,13 +2369,10 @@ void coap_startup(void) {
WSAStartup(wVersionRequested, &wsaData);
#endif
coap_clock_init();
#if defined(WITH_LWIP)
prng_init(LWIP_RAND());
#elif defined(WITH_CONTIKI)
prng_init(0);
#elif !defined(_WIN32)
prng_init(0);
#endif
coap_ticks(&now);
us = coap_ticks_to_rt_us(now);
/* Be accurate to the nearest (approx) us */
prng_init(us);
coap_dtls_startup();
}