summaryrefslogtreecommitdiff
path: root/ecp/src/dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'ecp/src/dir.c')
-rw-r--r--ecp/src/dir.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/ecp/src/dir.c b/ecp/src/dir.c
new file mode 100644
index 0000000..81f564e
--- /dev/null
+++ b/ecp/src/dir.c
@@ -0,0 +1,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);
+}