-try with finished
[oweals/gnunet.git] / src / dns / gnunet-dns-redirector.c
index 4eabc8c79a4a01aa3b9638b3a8dc737b35027d37..a45b8960950acae8baf20b3960a96b34865df037 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "platform.h"
 #include "gnunet_util_lib.h"
-#include "gnunet_dns_service-new.h"
+#include "gnunet_dns_service.h"
 #include "gnunet_dnsparser_lib.h"
 
 /**
@@ -56,9 +56,9 @@ static int verbosity;
 
 
 /**
- * Output the given DNS query to stdout.
+ * Modify the given DNS record.
  *
- * @param query query to display.
+ * @param record record to modify
  */
 static void
 modify_record (const struct GNUNET_DNSPARSER_Record *record)
@@ -77,7 +77,7 @@ modify_record (const struct GNUNET_DNSPARSER_Record *record)
                 "Changing A record from `%s' to `%s'\n",
                 inet_ntop (AF_INET, record->data.raw.data, buf, sizeof (buf)),
                 n4);
-      inet_pton (AF_INET, n4, record->data.raw.data);
+      GNUNET_assert (1 == inet_pton (AF_INET, n4, record->data.raw.data));
     }
     break;
   case GNUNET_DNSPARSER_TYPE_AAAA:
@@ -90,7 +90,7 @@ modify_record (const struct GNUNET_DNSPARSER_Record *record)
                 "Changing AAAA record from `%s' to `%s'\n",
                 inet_ntop (AF_INET6, record->data.raw.data, buf, sizeof (buf)),
                 n6);
-      inet_pton (AF_INET6, n6, record->data.raw.data);
+      GNUNET_assert (1 == inet_pton (AF_INET6, n6, record->data.raw.data));
     }
     break;
   case GNUNET_DNSPARSER_TYPE_NS:
@@ -199,6 +199,25 @@ static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  struct in_addr i4;
+  struct in6_addr i6;
+  if ( (n4 != NULL) &&
+       (1 != inet_pton (AF_INET, n4, &i4)) )
+  {
+    fprintf (stderr,
+            "`%s' is nto a valid IPv4 address!\n",
+            n4);
+    return;
+  }
+  if ( (n6 != NULL) &&
+       (1 != inet_pton (AF_INET6, n6, &i6)) )
+  {
+    fprintf (stderr,
+            "`%s' is nto a valid IPv6 address!\n",
+            n6);
+    return;
+  }
+
   handle =
     GNUNET_DNS_connect (cfg, 
                        GNUNET_DNS_FLAG_POST_RESOLUTION,