[pisa-src] r2519 - trunk/tools/dhcp/mac2ip.c

  • From: Christoph Viethen <christoph.viethen@xxxxxxxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Tue, 5 Apr 2011 04:53:11 +0200

Author: viethen
Date: Tue Apr  5 04:53:11 2011
New Revision: 2519

Log:
make use of new ip_bounds validity flags: initialize them to false, and
only set them to true when the looked-for value actually turns up in
the config file (can also now make good use of the recently-added return
value of string_to_ipv4_t())

Modified:
   trunk/tools/dhcp/mac2ip.c

Modified: trunk/tools/dhcp/mac2ip.c
==============================================================================
--- trunk/tools/dhcp/mac2ip.c   Tue Apr  5 04:38:45 2011        (r2518)
+++ trunk/tools/dhcp/mac2ip.c   Tue Apr  5 04:53:11 2011        (r2519)
@@ -8,6 +8,7 @@
 #include "mac2ip.h"
 #include <assert.h>
 #include <inttypes.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -162,6 +163,11 @@
     int    len;
     size_t buffsize = 100;
 
+    bounds->lower_client.valid  = false;
+    bounds->upper_client.valid  = false;
+    bounds->lower_service.valid = false;
+    bounds->upper_service.valid = false;
+
     fp = fopen(CONFIG_FILE_LOCATION, "r");
 
     if (!fp) {
@@ -211,26 +217,35 @@
 
 
         if (strcmp(variable, "lower_client_ip_bound") == 0) {
-            string_to_ipv4_t(value, &bounds->lower_client.bound);
-            retval++;
+            if (string_to_ipv4_t(value, &bounds->lower_client.bound) == 0) {
+                bounds->lower_client.valid = true;
+                retval++;
+            }
             continue;
         }
 
         if (strcmp(variable, "upper_client_ip_bound") == 0) {
-            string_to_ipv4_t(value, &bounds->upper_client.bound);
-            retval++;
+            if (string_to_ipv4_t(value, &bounds->upper_client.bound) == 0) {
+                bounds->upper_client.valid = true;
+                retval++;
+            }
             continue;
         }
 
         if (strcmp(variable, "lower_service_ip_bound") == 0) {
-            string_to_ipv4_t(value, &bounds->lower_service.bound);
-            retval++;
+            if (string_to_ipv4_t(value, &bounds->lower_service.bound) == 0) {
+                bounds->lower_service.valid = true;
+                retval++;
+            }
             continue;
         }
 
         if (strcmp(variable, "upper_service_ip_bound") == 0) {
-            string_to_ipv4_t(value, &bounds->upper_service.bound);
-            retval++;
+            if (string_to_ipv4_t(value, &bounds->upper_service.bound) == 0) {
+                bounds->upper_service.valid = true;
+                retval++;
+            }
+            continue;
         }
     }
 
@@ -264,8 +279,10 @@
      *  somewhere out of the space of all IPv4 addresses */
     hash_mac_to_rnd_ip_OAAT(mac, ip);
 
-    /* we want to read at least 4 IPs */
-    if (read_ip_bounds(&bounds) >= 2) {
+    /* we need two specific IP bounds */
+    if (read_ip_bounds(&bounds) < 0 ||
+        bounds.lower_client.valid == false ||
+        bounds.upper_client.valid == false) {
         printf("ERROR reading ip-bounds!\n");
         return -1;
     }
-- 
This is the pisa developer mailing list. Please also subscribe to the main pisa 
list at:
//www.freelists.org/list/pisa

Other related posts:

  • » [pisa-src] r2519 - trunk/tools/dhcp/mac2ip.c - Christoph Viethen