]> git.meshlink.io Git - meshlink/blobdiff - src/adns.c
Properly initialize mutexes and condition variables.
[meshlink] / src / adns.c
index 2776a4c5494bfa562ecb4163812c89740d925957..cb9611e1594b246ab71f8364ef624d33d2ddf3b4 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdatomic.h>
 
 #include "adns.h"
+#include "devtools.h"
 #include "logger.h"
 #include "xalloc.h"
 
@@ -48,6 +49,7 @@ static void *adns_loop(void *data) {
 
                if(time(NULL) < item->deadline) {
                        logger(mesh, MESHLINK_DEBUG, "Resolving %s port %s", item->host, item->serv);
+                       devtool_adns_resolve_probe();
                        int result = getaddrinfo(item->host, item->serv, NULL, &item->ai);
 
                        if(result) {
@@ -136,15 +138,22 @@ struct adns_blocking_info {
        char *host;
        char *serv;
        struct addrinfo *ai;
+       int socktype;
        bool done;
 };
 
-void *adns_blocking_handler(void *data) {
+static void *adns_blocking_handler(void *data) {
        struct adns_blocking_info *info = data;
 
        logger(info->mesh, MESHLINK_DEBUG, "Resolving %s port %s", info->host, info->serv);
+       devtool_adns_resolve_probe();
 
-       if(getaddrinfo(info->host, info->serv, NULL, &info->ai)) {
+       struct addrinfo hint = {
+               .ai_family = AF_UNSPEC,
+               .ai_socktype = info->socktype,
+       };
+
+       if(getaddrinfo(info->host, info->serv, &hint, &info->ai)) {
                info->ai = NULL;
        }
 
@@ -168,12 +177,15 @@ void *adns_blocking_handler(void *data) {
        return NULL;
 }
 
-struct addrinfo *adns_blocking_request(meshlink_handle_t *mesh, char *host, char *serv, int timeout) {
+struct addrinfo *adns_blocking_request(meshlink_handle_t *mesh, char *host, char *serv, int socktype, int timeout) {
        struct adns_blocking_info *info = xzalloc(sizeof(*info));
 
        info->mesh = mesh;
        info->host = host;
        info->serv = serv;
+       info->socktype = socktype;
+       pthread_mutex_init(&info->mutex, NULL);
+       pthread_cond_init(&info->cond, NULL);
 
        struct timespec deadline;
        clock_gettime(CLOCK_REALTIME, &deadline);