ftbfs
[oweals/gnunet.git] / src / dns / gnunet-dns-redirector.c
index 3df2ac21a0883ba23a056e64ebce915f735e3c0c..608540e12d3b25c03b4a82709f395abf9b8963a0 100644 (file)
@@ -1,21 +1,21 @@
 /*
      This file is part of GNUnet.
-     (C) 2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2011 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 
 /**
@@ -52,7 +52,7 @@ static int ret;
 /**
  * Selected level of verbosity.
  */
-static int verbosity;
+static unsigned int verbosity;
 
 
 /**
@@ -67,13 +67,13 @@ modify_record (const struct GNUNET_DNSPARSER_Record *record)
 
   switch (record->type)
   {
-  case GNUNET_DNSPARSER_TYPE_A:    
+  case GNUNET_DNSPARSER_TYPE_A:
     if (record->data.raw.data_len != sizeof (struct in_addr))
       return;
     if (NULL != n4)
     {
       if (verbosity > 1)
-       fprintf (stderr, 
+       fprintf (stderr,
                 "Changing A record from `%s' to `%s'\n",
                 inet_ntop (AF_INET, record->data.raw.data, buf, sizeof (buf)),
                 n4);
@@ -86,7 +86,7 @@ modify_record (const struct GNUNET_DNSPARSER_Record *record)
     if (NULL != n6)
     {
       if (verbosity > 1)
-       fprintf (stderr, 
+       fprintf (stderr,
                 "Changing AAAA record from `%s' to `%s'\n",
                 inet_ntop (AF_INET6, record->data.raw.data, buf, sizeof (buf)),
                 n6);
@@ -129,7 +129,7 @@ modify_record (const struct GNUNET_DNSPARSER_Record *record)
  * @param request_length number of bytes in request
  * @param request udp payload of the DNS request
  */
-static void 
+static void
 modify_request (void *cls,
                struct GNUNET_DNS_RequestHandle *rh,
                size_t request_length,
@@ -156,7 +156,7 @@ modify_request (void *cls,
   if (GNUNET_OK != ret)
   {
     if (GNUNET_NO == ret)
-      fprintf (stderr, 
+      fprintf (stderr,
               "Modified DNS response did not fit, keeping old response\n");
     else
       GNUNET_break (0); /* our modifications should have been sane! */
@@ -169,7 +169,7 @@ modify_request (void *cls,
               "Injecting modified DNS response\n");
     GNUNET_DNS_request_answer (rh, len, buf);
   }
-  GNUNET_free_non_null (buf);      
+  GNUNET_free_non_null (buf);
 }
 
 
@@ -177,7 +177,7 @@ modify_request (void *cls,
  * Shutdown.
  */
 static void
-do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_disconnect (void *cls)
 {
   if (NULL != handle)
   {
@@ -219,26 +219,31 @@ run (void *cls, char *const *args, const char *cfgfile,
   }
 
   handle =
-    GNUNET_DNS_connect (cfg, 
+    GNUNET_DNS_connect (cfg,
                        GNUNET_DNS_FLAG_POST_RESOLUTION,
                        &modify_request,
                        NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                               &do_disconnect, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL);
 }
 
 
 int
 main (int argc, char *const *argv)
 {
-  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
-    {'4', "ipv4", "IPV4",
-     gettext_noop ("set A records"),
-     1, &GNUNET_GETOPT_set_string, &n4},
-    {'6', "ipv4", "IPV6",
-     gettext_noop ("set AAAA records"),
-     1, &GNUNET_GETOPT_set_string, &n6},
-    GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
+  struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_option_string ('4',
+                                 "ipv4",
+                                 "IPV4",
+                                 gettext_noop ("set A records"),
+                                 &n4),
+
+    GNUNET_GETOPT_option_string ('6',
+                                 "ipv4",
+                                 "IPV6",
+                                 gettext_noop ("set AAAA records"),
+                                 &n6),
+
+    GNUNET_GETOPT_option_verbose (&verbosity),
     GNUNET_GETOPT_OPTION_END
   };