[pisa-src] r2518 - in trunk/tools/dhcp: mac2ip.c mac2ip.h

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

Author: viethen
Date: Tue Apr  5 04:38:45 2011
New Revision: 2518

Log:
change definition of the ip_bounds type to remove two shortcomings:

a) previously, none of the bounds values (being IPv4 addresses, stored
in a binary form) came with any qualification as to their validity; there
is no way to tell whether an IPv4 address, stored in a binary form,
is valid (for instance: has just been read from a config file), since
any four-byte value may look like a valid IPv4 address (even 0.0.0.0 might
be a valid bounds value, depending on definition); --> add a flag to
address this

b) choose explicit names for the four different kinds of bounds values:
using names instead of position within an array makes the whole affair
less error-prone, and, in this case, doesn't decrease efficiency in any
way.

Modified:
   trunk/tools/dhcp/mac2ip.c
   trunk/tools/dhcp/mac2ip.h

Modified: trunk/tools/dhcp/mac2ip.c
==============================================================================
--- trunk/tools/dhcp/mac2ip.c   Tue Apr  5 02:56:01 2011        (r2517)
+++ trunk/tools/dhcp/mac2ip.c   Tue Apr  5 04:38:45 2011        (r2518)
@@ -211,25 +211,25 @@
 
 
         if (strcmp(variable, "lower_client_ip_bound") == 0) {
-            string_to_ipv4_t(value, &bounds->bound[0]);
+            string_to_ipv4_t(value, &bounds->lower_client.bound);
             retval++;
             continue;
         }
 
         if (strcmp(variable, "upper_client_ip_bound") == 0) {
-            string_to_ipv4_t(value, &bounds->bound[1]);
+            string_to_ipv4_t(value, &bounds->upper_client.bound);
             retval++;
             continue;
         }
 
         if (strcmp(variable, "lower_service_ip_bound") == 0) {
-            string_to_ipv4_t(value, &bounds->bound[2]);
+            string_to_ipv4_t(value, &bounds->lower_service.bound);
             retval++;
             continue;
         }
 
         if (strcmp(variable, "upper_service_ip_bound") == 0) {
-            string_to_ipv4_t(value, &bounds->bound[3]);
+            string_to_ipv4_t(value, &bounds->upper_service.bound);
             retval++;
         }
     }
@@ -270,7 +270,7 @@
         return -1;
     }
 
-    adjust_ip_to_bounds(ip, &bounds.bound[1], &bounds.bound[0]);
+    adjust_ip_to_bounds(ip, &bounds.upper_client.bound, 
&bounds.lower_client.bound);
 
     return 0;
 }

Modified: trunk/tools/dhcp/mac2ip.h
==============================================================================
--- trunk/tools/dhcp/mac2ip.h   Tue Apr  5 02:56:01 2011        (r2517)
+++ trunk/tools/dhcp/mac2ip.h   Tue Apr  5 04:38:45 2011        (r2518)
@@ -22,22 +22,24 @@
 
 #include <stdint.h>
 
-typedef struct mac2ip_ipv4_t{
+typedef struct mac2ip_ipv4_t {
     uint8_t x[4];
 } mac2ip_ipv4_t;
 
-typedef struct mac2ip_mac_t{
+typedef struct mac2ip_mac_t {
     uint8_t x[6];
 } mac2ip_mac_t;
 
+struct ip_bound {
+    mac2ip_ipv4_t bound;
+    _Bool         valid;
+};
+
 typedef struct ip_bounds {
-    /*
-     * lower client's ip bound  := 0
-     * upper client's ip bound  := 1
-     * lower service's ip bound := 2
-     * upper service's ip bound := 3
-     */
-    mac2ip_ipv4_t bound[4];
+    struct ip_bound lower_client;
+    struct ip_bound upper_client;
+    struct ip_bound lower_service;
+    struct ip_bound upper_service;
 } ip_bounds;
 
 /*
-- 
This is the pisa developer mailing list. Please also subscribe to the main pisa 
list at:
//www.freelists.org/list/pisa

Other related posts: