Updating this patch to reflect the change made in a previous post
to another patch affecting the same area of code.

-- 
Horms
  H: http://www.vergenet.net/~horms/
  W: http://www.valinux.co.jp/en/

[IPv6addr] scan address directly into integers in scan_if()

This simplifies the addresss reading code a little by scanning
it directly into 4 32bit unsigned integers which are then converted
into network byte order.

The former construction of scaning the address into 8 strings, each
representing 16bits, and then using sfprintf to write these into
a buffer as integers seems a little bit akward to me.

Index: heartbeat-ipv6addr/resources/OCF/IPv6addr.c
===================================================================
--- heartbeat-ipv6addr.orig/resources/OCF/IPv6addr.c    2007-04-16 
16:55:31.000000000 +0900
+++ heartbeat-ipv6addr/resources/OCF/IPv6addr.c 2007-04-16 17:02:27.000000000 
+0900
@@ -432,12 +432,11 @@
 scan_if(struct in6_addr* addr_target, int* plen_target, int use_mask)
 {
        FILE *f;
-       char addr6[40];
        static char devname[21]="";
        struct in6_addr addr;
        struct in6_addr mask;
        unsigned int plen, scope, dad_status, if_idx;
-       char addr6p[8][5];
+       unsigned int addr6p[4];
 
        /* open /proc/net/if_inet6 file */
        if ((f = fopen(IF_INET6, "r")) == NULL) {
@@ -451,24 +450,18 @@
                int             s;
                gboolean        same = TRUE;
 
-               i = fscanf(f,
-                      "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n",
-                      addr6p[0], addr6p[1], addr6p[2], addr6p[3],
-                              addr6p[4], addr6p[5], addr6p[6], addr6p[7],
-                      &if_idx, &plen, &scope, &dad_status, devname);
+               i = fscanf(f, "%08x%08x%08x%08x %02x %02x %02x %02x %20s\n",
+                          &addr6p[0], &addr6p[1], &addr6p[2], &addr6p[3],
+                          &if_idx, &plen, &scope, &dad_status, devname);
                if (i == EOF) {
                        break;
                }
-               else if (i != 13) {
+               else if (i != 9) {
                        cl_log(LOG_INFO, "Error parsing %s, "
                               "perhaps the format has changed\n", IF_INET6);
                        break;
                }
 
-               sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s",
-                       addr6p[0], addr6p[1], addr6p[2], addr6p[3],
-                       addr6p[4], addr6p[5], addr6p[6], addr6p[7]);
-       
                /* Only Global address entry would be considered.
                 * maybe change?
                 */
@@ -483,9 +476,6 @@
                        continue;
                }
                *plen_target = plen;
-               
-               /* Convert string to sockaddr_in6 */
-               inet_pton(AF_INET6, addr6, &addr);
 
                /* Make the mask based on prefix length */
                memset(mask.s6_addr, 0xff, 16);
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to