do a dns-lookup to find the address of services other than localhost{4,6}
authorPhilipp Tölke <toelke@in.tum.de>
Sun, 18 Sep 2011 11:59:11 +0000 (11:59 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Sun, 18 Sep 2011 11:59:11 +0000 (11:59 +0000)
src/vpn/gnunet-daemon-exit.c

index 094ea749ffbcd4d6838c3bc978855cd767c2e63a..84a0e175aa75270e66e6053a0d077e49af7d920d 100644 (file)
@@ -674,8 +674,45 @@ read_service_conf (void *cls __attribute__ ((unused)), const char *section)
       }
       else
       {
-        // TODO Lookup, yadayadayada
-        GNUNET_assert (0);
+        struct addrinfo* res;
+        struct addrinfo hints;
+
+        hints.ai_flags |= AI_NUMERICHOST;
+
+        int ret = getaddrinfo(hostname, NULL, NULL, &res);
+
+        if (ret != 0)
+          {
+            GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No addresses found for %s!\n", hostname);
+            continue;
+          }
+        else
+          {
+            char buf[256];
+            struct addrinfo* c = res;
+
+            if(c)
+              {
+                if (c->ai_family == AF_INET)
+                  {
+                    serv->version = 4;
+                    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found %s as address for %s\n", inet_ntop(c->ai_family, &((struct sockaddr_in *)(c->ai_addr))->sin_addr, (char*)&buf, 256), hostname);
+                    memcpy(serv->v4.ip4address, &((struct sockaddr_in *)(c->ai_addr))->sin_addr, 4);
+                  }
+                else if (c->ai_family == AF_INET6)
+                  {
+                    serv->version = 6;
+                    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found %s as address for %s\n", inet_ntop(c->ai_family, &((struct sockaddr_in6*)(c->ai_addr))->sin6_addr, (char*)&buf, 256), hostname);
+                    memcpy(serv->v6.ip6address, &((struct sockaddr_in6 *)(c->ai_addr))->sin6_addr, 16);
+                  }
+              }
+            else
+              {
+                freeaddrinfo(res);
+                continue;
+              }
+            freeaddrinfo(res);
+          }
       }
       serv->remote_port = atoi (hostport);
       if (UDP == proto)