static char line[1024];
const char *end = strchr(*data, '\n');
- size_t len = end ? end - *data : strlen(*data);
+ size_t len = end ? (size_t)(end - *data) : strlen(*data);
if(len >= sizeof(line)) {
logger(NULL, MESHLINK_ERROR, "Maximum line length exceeded!\n");
return NULL;
}
static bool invitation_send(void *handle, uint8_t type, const void *data, size_t len) {
+ (void)type;
meshlink_handle_t *mesh = handle;
while(len) {
int result = send(mesh->sock, data, len, 0);
mesh->blen += result;
}
- if(newline - mesh->buffer >= len)
+ if((size_t)(newline - mesh->buffer) >= len)
return false;
len = newline - mesh->buffer;
blen = vsnprintf(buffer, sizeof(buffer), format, ap);
va_end(ap);
- if(blen < 1 || blen >= sizeof(buffer))
+ if(blen < 1 || (size_t)blen >= sizeof(buffer))
return false;
buffer[blen] = '\n';
};
const char *meshlink_strerror(meshlink_errno_t err) {
- if(err < 0 || err >= sizeof(errstr) / sizeof(*errstr))
+ if((int)err < 0 || err >= sizeof(errstr) / sizeof(*errstr))
return "Invalid error code";
return errstr[err];
}
}
static struct timeval idle(event_loop_t *loop, void *data) {
+ (void)loop;
meshlink_handle_t *mesh = data;
struct timeval t, tmin = {3600, 0};
for splay_each(node_t, n, mesh->nodes) {
usingname = true;
}
- if(devclass < 0 || devclass > _DEV_CLASS_MAX) {
+ if((int)devclass < 0 || devclass > _DEV_CLASS_MAX) {
logger(NULL, MESHLINK_ERROR, "Invalid devclass given!\n");
meshlink_errno = MESHLINK_EINVAL;
return NULL;
memset(hdr, 0, sizeof(*hdr));
// leave the last byte as 0 to make sure strings are always
// null-terminated if they are longer than the buffer
- strncpy(hdr->destination, destination->name, (sizeof(hdr)->destination) - 1);
- strncpy(hdr->source, mesh->self->name, (sizeof(hdr)->source) - 1);
+ strncpy((char *)hdr->destination, destination->name, (sizeof(hdr)->destination) - 1);
+ strncpy((char *)hdr->source, mesh->self->name, (sizeof(hdr)->source) - 1);
memcpy(packet->data + sizeof(*hdr), data, len);
}
void meshlink_send_from_queue(event_loop_t *loop, meshlink_handle_t *mesh) {
+ (void)loop;
vpn_packet_t *packet = meshlink_queue_pop(&mesh->outpacketqueue);
if(!packet)
return;
if(fread(buf + len - fsize - 1, fsize, 1, f) != 1) {
logger(mesh, MESHLINK_DEBUG, "Error reading from %s: %s\n", filename, strerror(errno));
fclose(f);
+ free(buf);
meshlink_errno = MESHLINK_ESTORAGE;
pthread_mutex_unlock(&(mesh->mesh_mutex));
return NULL;
if(host && port) {
xasprintf(&str, "%s %s", host, port);
if((strncmp("fe80", host, 4) != 0) && (strncmp("127.", host, 4) != 0) && (strcmp("localhost", host) != 0))
- append_config_file(mesh, node->name, "Address", str);
+ modify_config_file(mesh, node->name, "Address", str, 5);
else
logger(mesh, MESHLINK_DEBUG, "Not adding Link Local IPv6 Address to config\n");
}
// @TODO do we want to fire off a connection attempt right away?
}
-/* Return an array of edges in the current network graph.
- * Data captures the current state and will not be updated.
- * Caller must deallocate data when done.
- */
-meshlink_edge_t **meshlink_get_all_edges_state(meshlink_handle_t *mesh, meshlink_edge_t **edges, size_t *nmemb) {
- if(!mesh || !nmemb || (*nmemb && !edges)) {
- meshlink_errno = MESHLINK_EINVAL;
- return NULL;
- }
-
- pthread_mutex_lock(&(mesh->mesh_mutex));
-
- meshlink_edge_t **result = NULL;
- meshlink_edge_t *copy = NULL;
- int result_size = 0;
-
- result_size = mesh->edges->count;
-
- // if result is smaller than edges, we have to dealloc all the excess meshlink_edge_t
- if(result_size > *nmemb)
- result = realloc(edges, result_size * sizeof(meshlink_edge_t *));
- else
- result = edges;
-
- if(result) {
- meshlink_edge_t **p = result;
- int n = 0;
- for splay_each(edge_t, e, mesh->edges) {
- // skip edges that do not represent a two-directional connection
- if((!e->reverse) || (e->reverse->to != e->from)) {
- result_size--;
- continue;
- }
- n++;
- // the first *nmemb members of result can be re-used
- if(n > *nmemb)
- copy = xzalloc(sizeof(*copy));
- else
- copy = *p;
- copy->from = (meshlink_node_t *)e->from;
- copy->to = (meshlink_node_t *)e->to;
- copy->address = e->address.storage;
- copy->options = e->options;
- copy->weight = e->weight;
- *p++ = copy;
- }
- // shrink result to the actual amount of memory used
- for(int i = *nmemb; i > result_size; i--)
- free(result[i - 1]);
- result = realloc(result, result_size * sizeof(meshlink_edge_t *));
- *nmemb = result_size;
- } else {
- *nmemb = 0;
- meshlink_errno = MESHLINK_ENOMEM;
- }
-
- pthread_mutex_unlock(&(mesh->mesh_mutex));
-
- return result;
-}
-
static bool channel_pre_accept(struct utcp *utcp, uint16_t port) {
+ (void)port;
node_t *n = utcp->priv;
meshlink_handle_t *mesh = n->mesh;
return mesh->channel_accept_cb;
static ssize_t channel_send(struct utcp *utcp, const void *data, size_t len) {
node_t *n = utcp->priv;
meshlink_handle_t *mesh = n->mesh;
- return meshlink_send(mesh, (meshlink_node_t *)n, data, len) ? len : -1;
+ return meshlink_send(mesh, (meshlink_node_t *)n, data, len) ? (ssize_t)len : -1;
}
void meshlink_set_channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_channel_receive_cb_t cb) {
}
static void channel_receive(meshlink_handle_t *mesh, meshlink_node_t *source, const void *data, size_t len) {
+ (void)mesh;
node_t *n = (node_t *)source;
if(!n->utcp)
abort();
}
void meshlink_set_channel_poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_channel_poll_cb_t cb) {
+ (void)mesh;
channel->poll_cb = cb;
utcp_set_poll_cb(channel->c, cb ? channel_poll : NULL);
}
}
meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len, uint32_t flags) {
+ if(data || len)
+ abort(); // TODO: handle non-NULL data
+
if(!mesh || !node) {
meshlink_errno = MESHLINK_EINVAL;
return NULL;