aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.c
diff options
context:
space:
mode:
authorDavid Timber <mieabby@gmail.com>2020-01-11 18:03:47 +1100
committerDavid Timber <mieabby@gmail.com>2020-01-11 18:03:47 +1100
commit10512fc50e6184397206a41c157c09d9b02e9e1a (patch)
tree5f0779032edf0f0710400ae6c99b9a3f2977735d /src/protocol.c
parent129e12d7685a6ea99fde514ad104a0368a19033d (diff)
staged resolv_worker
* replaced RNG from `rnd` to `mbedtls_ctr_drbg` * use of `uint_fastN_t` where appropriate * heartbeat protocol draft * improved worker scheduling mech
Diffstat (limited to 'src/protocol.c')
-rw-r--r--src/protocol.c54
1 files changed, 41 insertions, 13 deletions
diff --git a/src/protocol.c b/src/protocol.c
index f063835..4e1da40 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -1,7 +1,11 @@
#include "protocol.h"
+
#include <string.h>
-const char *prne_arch2str (const prne_arch_t x) {
+#include <arpa/inet.h>
+
+
+const char *prne_arch_tostr (const prne_arch_t x) {
switch (x){
case PRNE_ARCH_ARMV4T:
return "armv4t";
@@ -30,40 +34,64 @@ const char *prne_arch2str (const prne_arch_t x) {
return NULL;
}
-prne_arch_t prne_str2arch (const char *str) {
- if (strcmp(str, prne_arch2str(PRNE_ARCH_ARMV4T)) == 0) {
+prne_arch_t prne_arch_fstr (const char *str) {
+ if (strcmp(str, prne_arch_tostr(PRNE_ARCH_ARMV4T)) == 0) {
return PRNE_ARCH_ARMV4T;
}
- else if (strcmp(str, prne_arch2str(PRNE_ARCH_ARMV7)) == 0) {
+ else if (strcmp(str, prne_arch_tostr(PRNE_ARCH_ARMV7)) == 0) {
return PRNE_ARCH_ARMV7;
}
- else if (strcmp(str, prne_arch2str(PRNE_ARCH_I686)) == 0) {
+ else if (strcmp(str, prne_arch_tostr(PRNE_ARCH_I686)) == 0) {
return PRNE_ARCH_I686;
}
- else if (strcmp(str, prne_arch2str(PRNE_ARCH_M68K)) == 0) {
+ else if (strcmp(str, prne_arch_tostr(PRNE_ARCH_M68K)) == 0) {
return PRNE_ARCH_M68K;
}
- else if (strcmp(str, prne_arch2str(PRNE_ARCH_MIPS)) == 0) {
+ else if (strcmp(str, prne_arch_tostr(PRNE_ARCH_MIPS)) == 0) {
return PRNE_ARCH_MIPS;
}
- else if (strcmp(str, prne_arch2str(PRNE_ARCH_MPSL)) == 0) {
+ else if (strcmp(str, prne_arch_tostr(PRNE_ARCH_MPSL)) == 0) {
return PRNE_ARCH_MPSL;
}
- else if (strcmp(str, prne_arch2str(PRNE_ARCH_PPC)) == 0) {
+ else if (strcmp(str, prne_arch_tostr(PRNE_ARCH_PPC)) == 0) {
return PRNE_ARCH_PPC;
}
- else if (strcmp(str, prne_arch2str(PRNE_ARCH_RV32)) == 0) {
+ else if (strcmp(str, prne_arch_tostr(PRNE_ARCH_RV32)) == 0) {
return PRNE_ARCH_RV32;
}
- else if (strcmp(str, prne_arch2str(PRNE_ARCH_RV64)) == 0) {
+ else if (strcmp(str, prne_arch_tostr(PRNE_ARCH_RV64)) == 0) {
return PRNE_ARCH_RV64;
}
- else if (strcmp(str, prne_arch2str(PRNE_ARCH_SH4)) == 0) {
+ else if (strcmp(str, prne_arch_tostr(PRNE_ARCH_SH4)) == 0) {
return PRNE_ARCH_SH4;
}
- else if (strcmp(str, prne_arch2str(PRNE_ARCH_SPC)) == 0) {
+ else if (strcmp(str, prne_arch_tostr(PRNE_ARCH_SPC)) == 0) {
return PRNE_ARCH_SPC;
}
return PRNE_ARCH_NONE;
}
+
+void prne_net_ep_tosin4 (const prne_net_endpoint_t *ep, struct sockaddr_in *out) {
+ memcpy(&out->sin_addr, ep->addr.addr, 4);
+ out->sin_family = AF_INET;
+ out->sin_port = htons(ep->port);
+}
+
+void prne_net_ep_tosin6 (const prne_net_endpoint_t *ep, struct sockaddr_in6 *out) {
+ memcpy(&out->sin6_addr, ep->addr.addr, 16);
+ out->sin6_family = AF_INET6;
+ out->sin6_port = htons(ep->port);
+}
+
+bool prne_net_ep_set_ipv4 (const char *str, const uint16_t port, prne_net_endpoint_t *out) {
+ out->port = port;
+ out->addr.ver = PRNE_IPV_4;
+ return inet_pton(AF_INET, str, &out->addr.addr) != 0;
+}
+
+bool prne_net_ep_set_ipv6 (const char *str, const uint16_t port, prne_net_endpoint_t *out) {
+ out->port = port;
+ out->addr.ver = PRNE_IPV_6;
+ return inet_pton(AF_INET6, str, &out->addr.addr) != 0;
+}