-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkeepalive.c
More file actions
25 lines (18 loc) · 739 Bytes
/
keepalive.c
File metadata and controls
25 lines (18 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "keepalive.h"
static void * init_keepalive(uint32_t priv_id, uint32_t pub_id, uint32_t counter) {
uint32_t * msg = (uint32_t *)calloc(sizeof(uint32_t), 5);
msg[0] = GUINT32_TO_LE(0x0001bef4);
msg[1] = GINT32_TO_LE(priv_id);
msg[2] = GINT32_TO_LE(pub_id);
msg[3] = GINT32_TO_LE(counter);
msg[4] = GINT32_TO_LE(crc_32(msg, sizeof(uint32_t) * 5, 0xEDB88320));
return msg;
}
static void destroy_keepalive(void * msg) {
free(msg);
}
void send_keepalive(uint32_t private_id, uint32_t public_id, uint32_t counter,int s, const struct sockaddr * to) {
uint8_t * msg = (uint8_t *)init_keepalive(private_id, public_id, counter);
sendto(s, msg, 5*sizeof(uint32_t), 0, to, sizeof(*to));
destroy_keepalive(msg);
}