X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink.c;h=66d87ee986cde60a8b3689fb0820b1bbbb7f0f51;hb=56e0dd5ad3936663d398500f80c9a502553659df;hp=84f6e29cf725897deb9b52e78460dbf5a0e8609a;hpb=a8c5d9fc9f1274608bf9b3a2430f3f72f00ecbcc;p=meshlink diff --git a/src/meshlink.c b/src/meshlink.c index 84f6e29c..66d87ee9 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1050,6 +1050,7 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const c mesh->confbase = xstrdup(confbase); mesh->appname = xstrdup(appname); mesh->devclass = devclass; + mesh->discovery = true; if(usingname) { mesh->name = xstrdup(name); @@ -1210,10 +1211,18 @@ void meshlink_stop(meshlink_handle_t *mesh) { event_loop_stop(&mesh->loop); // Send ourselves a UDP packet to kick the event loop - listen_socket_t *s = &mesh->listen_socket[0]; + for(int i = 0; i < mesh->listen_sockets; i++) { + sockaddr_t sa; + socklen_t salen = sizeof(sa.sa); - if(sendto(s->udp.fd, "", 1, MSG_NOSIGNAL, &s->sa.sa, SALEN(s->sa.sa)) == -1) { - logger(mesh, MESHLINK_ERROR, "Could not send a UDP packet to ourself"); + if(getsockname(mesh->listen_socket[i].udp.fd, &sa.sa, &salen) == -1) { + logger(mesh, MESHLINK_ERROR, "System call `%s' failed: %s", "getsockname", sockstrerror(sockerrno)); + continue; + } + + if(sendto(mesh->listen_socket[i].udp.fd, "", 1, MSG_NOSIGNAL, &sa.sa, salen) == -1) { + logger(mesh, MESHLINK_ERROR, "Could not send a UDP packet to ourself: %s", sockstrerror(sockerrno)); + } } // Wait for the main thread to finish