gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r5361 - GNUnet/src/util/network


From: gnunet
Subject: [GNUnet-SVN] r5361 - GNUnet/src/util/network
Date: Fri, 27 Jul 2007 02:59:56 -0600 (MDT)

Author: grothoff
Date: 2007-07-27 02:59:56 -0600 (Fri, 27 Jul 2007)
New Revision: 5361

Added:
   GNUnet/src/util/network/ipchecktest.c
Modified:
   GNUnet/src/util/network/Makefile.am
   GNUnet/src/util/network/ipcheck.c
Log:
see drupal 263

Modified: GNUnet/src/util/network/Makefile.am
===================================================================
--- GNUnet/src/util/network/Makefile.am 2007-07-27 08:26:18 UTC (rev 5360)
+++ GNUnet/src/util/network/Makefile.am 2007-07-27 08:59:56 UTC (rev 5361)
@@ -19,6 +19,7 @@
 libnetwork_la_LIBADD = $(ADNS_LINK)
 
 check_PROGRAMS = \
+ ipchecktest \
  selecttest 
 
 TESTS = $(check_PROGRAMS)
@@ -29,3 +30,10 @@
  $(top_builddir)/src/util/libgnunetutil.la
 
 
+
+ipchecktest_SOURCES = \
+ ipchecktest.c 
+ipchecktest_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la
+
+

Modified: GNUnet/src/util/network/ipcheck.c
===================================================================
--- GNUnet/src/util/network/ipcheck.c   2007-07-27 08:26:18 UTC (rev 5360)
+++ GNUnet/src/util/network/ipcheck.c   2007-07-27 08:59:56 UTC (rev 5361)
@@ -138,7 +138,7 @@
             =
             htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
                    temps[3]);
-          if ((slash <= 32) && (slash > 0))
+          if ((slash <= 32) && (slash >= 0))
             {
               result[i].netmask.addr = 0;
               while (slash > 0)
@@ -165,6 +165,40 @@
               return NULL;      /* error */
             }
         }
+      /* try third notation */
+      slash = 32;
+      cnt = sscanf (&routeList[pos],
+                    "%u.%u.%u.%u;",
+                    &temps[0], &temps[1], &temps[2], &temps[3]);
+      if (cnt == 4)
+        {
+          for (j = 0; j < 4; j++)
+            if (temps[j] > 0xFF)
+              {
+                GE_LOG (ectx,
+                        GE_ERROR | GE_USER | GE_IMMEDIATE,
+                        _("Invalid format for IP: `%s'\n"), &routeList[pos]);
+                FREE (result);
+                return NULL;
+              }
+          result[i].network.addr
+            =
+            htonl ((temps[0] << 24) + (temps[1] << 16) + (temps[2] << 8) +
+                   temps[3]);
+         result[i].netmask.addr = 0;
+         while (slash > 0)
+           {
+             result[i].netmask.addr
+               = (result[i].netmask.addr >> 1) + 0x80000000;
+             slash--;
+           }
+         result[i].netmask.addr = htonl (result[i].netmask.addr);
+         while (routeList[pos] != ';')
+           pos++;
+         pos++;
+         i++;
+         continue;
+        }
       GE_LOG (ectx,
               GE_ERROR | GE_USER | GE_IMMEDIATE,
               _("Invalid format for IP: `%s'\n"), &routeList[pos]);

Added: GNUnet/src/util/network/ipchecktest.c
===================================================================
--- GNUnet/src/util/network/ipchecktest.c                               (rev 0)
+++ GNUnet/src/util/network/ipchecktest.c       2007-07-27 08:59:56 UTC (rev 
5361)
@@ -0,0 +1,61 @@
+/*
+     This file is part of GNUnet.
+     (C) 2007 Christian Grothoff (and other contributing authors)
+
+     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 2, 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.
+
+     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.
+*/
+
+/**
+ * @file util/network/ipchecktest.c
+ * @brief testcase for util/network/ipcheck.c
+ */
+
+#include "gnunet_util.h"
+#include "platform.h"
+
+int test() 
+{
+  struct CIDRNetwork * cidr;
+
+  cidr = parse_ipv4_network_specification(NULL,
+                                         "127.0.0.1;");
+  if (cidr == NULL)
+    return 1;
+  FREE(cidr);
+  cidr = parse_ipv4_network_specification(NULL,
+                                         "127.0.0.1/8;");
+  if (cidr == NULL)
+    return 2;
+  FREE(cidr);
+  cidr = parse_ipv4_network_specification(NULL,
+                                         "0.0.0.0/0;");
+  if (cidr == NULL)
+    return 4;
+  FREE(cidr);
+  return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+  int ret;
+  ret = test ();
+  if (ret != 0)
+    fprintf (stderr, "ERROR %d.\n", ret);
+  return ret;
+}
+
+/* end of ipchecktest.c */


Property changes on: GNUnet/src/util/network/ipchecktest.c
___________________________________________________________________
Name: svn:eol-style
   + native





reply via email to

[Prev in Thread] Current Thread [Next in Thread]