#define UDPC_BAD_MODE_SEND_INTERVAL (1.0f/10.0f)
#define UDPC_TIMEOUT_SECONDS 10.0f
#define UDPC_HEARTBEAT_PKT_INTERVAL (15.0f/100.0f)
-#define UDPC_INIT_PKT_INTERVAL 5.0f
+#define UDPC_INIT_PKT_INTERVAL 5
+#define UDPC_INIT_PKT_INTERVAL_F ((float)UDPC_INIT_PKT_INTERVAL)
#define UDPC_PKT_PROTOCOL_ID 1357924680
#define UDPC_ID_CONNECT 0x80000000
};
timespec_get(&cd.received, TIME_UTC);
- // only set "received" to now, since "sent" will be set after sending packet
+ cd.sent = cd.received;
+ cd.sent.tv_sec -= UDPC_INIT_PKT_INTERVAL + 1;
UDPC_HashMap_insert(ctx->conMap, addr, &cd);
}
if((cd->flags & 0x8) != 0)
{
// initiate connection to server
- if(UDPC_INTERNAL_ts_diff(&us->tsNow, &cd->sent) < UDPC_INIT_PKT_INTERVAL)
+ if(UDPC_INTERNAL_ts_diff(&us->tsNow, &cd->sent) < UDPC_INIT_PKT_INTERVAL_F)
{
return;
}
int index = 0;
for(int x = 0; x < 4; ++x)
{
- unsigned char temp = (addr >> (24 - x * 8)) & 0xFF;
+ unsigned char temp = (addr >> (x * 8)) & 0xFF;
if(temp >= 100)
{
}
else if(*addrStr == '.' && temp <= 0xFF && index < 3)
{
- addr |= (temp << (24 - 8 * index++));
+ addr |= (temp << (8 * index++));
temp = 0;
}
else
if(index == 3 && temp <= 0xFF)
{
- addr |= temp;
+ addr |= temp << 24;
return addr;
}
else
{
UDPC_Context ctx;
ASSERT_EQ_MEM(
- UDPC_INTERNAL_atostr(&ctx, (0xAC << 24) | (0x1E << 16) | (0x1 << 8) | 0xFF),
+ UDPC_INTERNAL_atostr(&ctx, (0xFF << 24) | (0x1 << 16) | (0x1E << 8) | 0xAC),
"172.30.1.255",
13);
UNITTEST_REPORT(ATOSTR);
void TEST_STRTOA()
{
- ASSERT_EQ(0x01020304, UDPC_strtoa("1.2.3.4"));
- ASSERT_EQ(0x7F000001, UDPC_strtoa("127.0.0.1"));
- ASSERT_EQ(0xC0A801FF, UDPC_strtoa("192.168.1.255"));
+ ASSERT_EQ(0x04030201, UDPC_strtoa("1.2.3.4"));
+ ASSERT_EQ(0x0100007F, UDPC_strtoa("127.0.0.1"));
+ ASSERT_EQ(0xFF01A8C0, UDPC_strtoa("192.168.1.255"));
ASSERT_EQ(0, UDPC_strtoa("1.2.3.4.5"));
ASSERT_EQ(0, UDPC_strtoa("100.20.30"));
ASSERT_EQ(0, UDPC_strtoa("200.400.30.50"));