+ result = xzalloc(*nmemb * sizeof (meshlink_edge_t*));
+
+ if(result) {
+ meshlink_edge_t **p = result;
+ 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)) {
+ *nmemb--;
+ continue;
+ }
+ // copy the edge so it can't be mutated
+ copy = xzalloc(sizeof *copy);
+ copy->from = (meshlink_node_t*)e->from;
+ copy->to = (meshlink_node_t*)e->to;
+#ifdef HAVE_STRUCT_SOCKADDR_STORAGE
+ copy->address = e->address.storage;
+#endif
+ copy->options = e->options;
+ copy->weight = e->weight;
+ *p++ = copy;
+ }
+ // shrink result to the actual amount of memory used
+ result = realloc(result, *nmemb * sizeof (meshlink_edge_t*));
+ } else {
+ *nmemb = 0;
+ meshlink_errno = MESHLINK_ENOMEM;
+ }
+
+ pthread_mutex_unlock(&(mesh->mesh_mutex));
+
+ return result;