brianp      02/05/04 22:54:51

  Modified:    network_io/unix inet_ntop.c
  Log:
  Formatting fixes only
  
  Revision  Changes    Path
  1.15      +97 -87    apr/network_io/unix/inet_ntop.c
  
  Index: inet_ntop.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/inet_ntop.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- inet_ntop.c       5 May 2002 05:48:28 -0000       1.14
  +++ inet_ntop.c       5 May 2002 05:54:51 -0000       1.15
  @@ -139,95 +139,105 @@
   static const char *
   inet_ntop6(const unsigned char *src, char *dst, apr_size_t size)
   {
  -     /*
  -      * Note that int32_t and int16_t need only be "at least" large enough
  -      * to contain a value of the specified size.  On some systems, like
  -      * Crays, there is no such thing as an integer variable with 16 bits.
  -      * Keep this in mind if you think this function should have been coded
  -      * to use pointer overlays.  All the world's not a VAX.
  -      */
  -     char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
  -     struct { int base, len; } best, cur;
  -     unsigned int words[IN6ADDRSZ / INT16SZ];
  -     int i;
  -        const unsigned char *next_src, *src_end;
  -        unsigned int *next_dest;
  +    /*
  +     * Note that int32_t and int16_t need only be "at least" large enough
  +     * to contain a value of the specified size.  On some systems, like
  +     * Crays, there is no such thing as an integer variable with 16 bits.
  +     * Keep this in mind if you think this function should have been coded
  +     * to use pointer overlays.  All the world's not a VAX.
  +     */
  +    char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
  +    struct { int base, len; } best, cur;
  +    unsigned int words[IN6ADDRSZ / INT16SZ];
  +    int i;
  +    const unsigned char *next_src, *src_end;
  +    unsigned int *next_dest;
   
  -     /*
  -      * Preprocess:
  -      *      Copy the input (bytewise) array into a wordwise array.
  -      *      Find the longest run of 0x00's in src[] for :: shorthanding.
  -      */
  -        next_src = src;
  -        src_end = src + IN6ADDRSZ;
  -        next_dest = words;
  -        do {
  -            unsigned int next_word = (unsigned int)*next_src++;
  -            next_word <<= 8;
  -            next_word |= (unsigned int)*next_src++;
  -            *next_dest++ = next_word;
  -        } while (next_src < src_end);
  -     best.base = -1;
  -     cur.base = -1;
  -     for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
  -             if (words[i] == 0) {
  -                     if (cur.base == -1)
  -                             cur.base = i, cur.len = 1;
  -                     else
  -                             cur.len++;
  -             } else {
  -                     if (cur.base != -1) {
  -                             if (best.base == -1 || cur.len > best.len)
  -                                     best = cur;
  -                             cur.base = -1;
  -                     }
  -             }
  -     }
  -     if (cur.base != -1) {
  -             if (best.base == -1 || cur.len > best.len)
  -                     best = cur;
  -     }
  -     if (best.base != -1 && best.len < 2)
  -             best.base = -1;
  +    /*
  +     * Preprocess:
  +     *       Copy the input (bytewise) array into a wordwise array.
  +     *       Find the longest run of 0x00's in src[] for :: shorthanding.
  +     */
  +    next_src = src;
  +    src_end = src + IN6ADDRSZ;
  +    next_dest = words;
  +    do {
  +        unsigned int next_word = (unsigned int)*next_src++;
  +        next_word <<= 8;
  +        next_word |= (unsigned int)*next_src++;
  +        *next_dest++ = next_word;
  +    } while (next_src < src_end);
  +    best.base = -1;
  +    cur.base = -1;
  +    for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
  +        if (words[i] == 0) {
  +            if (cur.base == -1) {
  +                cur.base = i;
  +                cur.len = 1;
  +            }
  +            else {
  +                cur.len++;
  +            }
  +        } else {
  +            if (cur.base != -1) {
  +                if (best.base == -1 || cur.len > best.len) {
  +                    best = cur;
  +                }
  +                cur.base = -1;
  +            }
  +        }
  +    }
  +    if (cur.base != -1) {
  +        if (best.base == -1 || cur.len > best.len) {
  +            best = cur;
  +        }
  +    }
  +    if (best.base != -1 && best.len < 2) {
  +        best.base = -1;
  +    }
   
  -     /*
  -      * Format the result.
  -      */
  -     tp = tmp;
  -     for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
  -             /* Are we inside the best run of 0x00's? */
  -             if (best.base != -1 && i >= best.base &&
  -                 i < (best.base + best.len)) {
  -                     if (i == best.base)
  -                             *tp++ = ':';
  -                     continue;
  -             }
  -             /* Are we following an initial run of 0x00s or any real hex? */
  -             if (i != 0)
  -                     *tp++ = ':';
  -             /* Is this address an encapsulated IPv4? */
  -             if (i == 6 && best.base == 0 &&
  -                 (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
  -                     if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
  -                             return (NULL);
  -                     tp += strlen(tp);
  -                     break;
  -             }
  -             tp += apr_snprintf(tp, sizeof tmp - (tp - tmp), "%x", words[i]);
  -     }
  -     /* Was it a trailing run of 0x00's? */
  -     if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ))
  -             *tp++ = ':';
  -     *tp++ = '\0';
  +    /*
  +     * Format the result.
  +     */
  +    tp = tmp;
  +    for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
  +        /* Are we inside the best run of 0x00's? */
  +        if (best.base != -1 && i >= best.base &&
  +            i < (best.base + best.len)) {
  +            if (i == best.base) {
  +                *tp++ = ':';
  +            }
  +            continue;
  +        }
  +        /* Are we following an initial run of 0x00s or any real hex? */
  +        if (i != 0) {
  +            *tp++ = ':';
  +        }
  +        /* Is this address an encapsulated IPv4? */
  +        if (i == 6 && best.base == 0 &&
  +            (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
  +            if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) {
  +                return (NULL);
  +            }
  +            tp += strlen(tp);
  +            break;
  +        }
  +        tp += apr_snprintf(tp, sizeof tmp - (tp - tmp), "%x", words[i]);
  +    }
  +    /* Was it a trailing run of 0x00's? */
  +    if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) {
  +        *tp++ = ':';
  +    }
  +    *tp++ = '\0';
   
  -     /*
  -      * Check for overflow, copy, and we're done.
  -      */
  -     if ((size_t)(tp - tmp) > size) {
  -             errno = ENOSPC;
  -             return (NULL);
  -     }
  -     strcpy(dst, tmp);
  -     return (dst);
  +    /*
  +     * Check for overflow, copy, and we're done.
  +     */
  +    if ((size_t)(tp - tmp) > size) {
  +        errno = ENOSPC;
  +        return (NULL);
  +    }
  +    strcpy(dst, tmp);
  +    return (dst);
   }
   #endif
  
  
  

Reply via email to