blob: 81f564e38b0df47689d9ef565f5869e5ac311021 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#include "core.h"
#include "cr.h"
#include "dir.h"
void ecp_dir_parse_item(unsigned char *buf, ECPDirItem *item) {
ecp_cr_dh_pub_from_buf(&item->node.public, buf);
buf += ECP_ECDH_SIZE_KEY;
memcpy(&item->node.addr.host, buf, sizeof(item->node.addr));
buf += ECP_IPv4_ADDR_SIZE;
item->node.addr.port = \
(buf[0] << 8) | \
(buf[1]);
buf += sizeof(uint16_t);
item->capabilities = \
(buf[0] << 8) | \
(buf[1]);
buf += sizeof(uint16_t);
}
void ecp_dir_serialize_item(unsigned char *buf, ECPDirItem *item) {
ecp_cr_dh_pub_to_buf(buf, &item->node.public);
buf += ECP_ECDH_SIZE_KEY;
memcpy(buf, &item->node.addr.host, sizeof(item->node.addr));
buf += ECP_IPv4_ADDR_SIZE;
buf[0] = (item->node.addr.port & 0xFF00) >> 8;
buf[1] = (item->node.addr.port & 0x00FF);
buf += sizeof(uint16_t);
buf[0] = (item->capabilities & 0xFF00) >> 8;
buf[1] = (item->capabilities & 0x00FF);
buf += sizeof(uint16_t);
}
|