handling replies continuously from server
[oweals/gnunet.git] / src / dns / gnunet-dns-monitor.c
index 96d2a4959bd21e477ea9d3e6f9bc02ce0514bf80..82715aabc3d3a8b3e243879e9a3dc2ec481f773b 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"
 
 /**
 static struct GNUNET_DNS_Handle *handle;
 
 /**
- * Option -s.
+ * Option -i.
  */
-static int benchmark_send;
+static int inbound_only;
+
+/**
+ * Option -o.
+ */
+static int outbound_only;
 
 /**
  * Global return value (0 success).
@@ -114,9 +119,9 @@ display_query (const struct GNUNET_DNSPARSER_Query *query)
 
 
 /**
- * Output the given DNS query to stdout.
+ * Output the given DNS record to stdout.
  *
- * @param query query to display.
+ * @param record record to display.
  */
 static void
 display_record (const struct GNUNET_DNSPARSER_Record *record)
@@ -129,16 +134,16 @@ display_record (const struct GNUNET_DNSPARSER_Record *record)
   switch (record->type)
   {
   case GNUNET_DNSPARSER_TYPE_A:
-    if (record->data_len != sizeof (struct in_addr))
+    if (record->data.raw.data_len != sizeof (struct in_addr))
       format = "<invalid>";
     else
-      format = inet_ntop (AF_INET, record->data.raw, buf, sizeof (buf));
+      format = inet_ntop (AF_INET, record->data.raw.data, buf, sizeof (buf));
     break;
   case GNUNET_DNSPARSER_TYPE_AAAA:
-    if (record->data_len != sizeof (struct in6_addr))
+    if (record->data.raw.data_len != sizeof (struct in6_addr))
       format = "<invalid>";
     else
-      format = inet_ntop (AF_INET6, record->data.raw, buf, sizeof (buf));
+      format = inet_ntop (AF_INET6, record->data.raw.data, buf, sizeof (buf));
     break;
   case GNUNET_DNSPARSER_TYPE_NS:
   case GNUNET_DNSPARSER_TYPE_CNAME:
@@ -177,8 +182,8 @@ display_record (const struct GNUNET_DNSPARSER_Record *record)
   case GNUNET_DNSPARSER_TYPE_TXT:
     GNUNET_asprintf (&tmp,
                     "%.*s",
-                    (unsigned int) record->data_len,
-                    record->data.raw);
+                    (unsigned int) record->data.raw.data_len,
+                    record->data.raw.data);
     format = tmp;
     break;
   default:
@@ -186,12 +191,11 @@ display_record (const struct GNUNET_DNSPARSER_Record *record)
     break;
   }
   fprintf (stdout,
-          "\t\t%s %s: %s = %s (%u bytes, %u s)\n",
+          "\t\t%s %s: %s = %s (%u s)\n",
           get_class (record->class),
           get_type (record->type),
           record->name,
           format,
-          (unsigned int) record->data_len,
           (unsigned int) (GNUNET_TIME_absolute_get_remaining (record->expiration_time).rel_value / 1000));
   GNUNET_free_non_null (tmp);
 }
@@ -306,9 +310,18 @@ static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  enum GNUNET_DNS_Flags flags;
+
+  flags = GNUNET_DNS_FLAG_REQUEST_MONITOR | GNUNET_DNS_FLAG_RESPONSE_MONITOR;
+  if (inbound_only | outbound_only)
+    flags = 0;
+  if (inbound_only)
+    flags |= GNUNET_DNS_FLAG_REQUEST_MONITOR;
+  if (outbound_only)
+    flags |= GNUNET_DNS_FLAG_RESPONSE_MONITOR;
   handle =
     GNUNET_DNS_connect (cfg, 
-                       GNUNET_DNS_FLAG_REQUEST_MONITOR | GNUNET_DNS_FLAG_RESPONSE_MONITOR,
+                       flags,
                        &display_request,
                        NULL);
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
@@ -320,9 +333,12 @@ int
 main (int argc, char *const *argv)
 {
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
-    {'s', "testoption", NULL,
-     gettext_noop ("not useful"),
-     0, &GNUNET_GETOPT_set_one, &benchmark_send},
+    {'i', "inbound-only", NULL,
+     gettext_noop ("only monitor DNS queries"),
+     0, &GNUNET_GETOPT_set_one, &inbound_only},
+    {'o', "outbound-only", NULL,
+     gettext_noop ("only monitor DNS replies"),
+     0, &GNUNET_GETOPT_set_one, &outbound_only},
     GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
     GNUNET_GETOPT_OPTION_END
   };