]> The Tcpdump Group git mirrors - tcpdump/blobdiff - addrtostr.c
change make check to work with POSIX shell
[tcpdump] / addrtostr.c
index 92875622e361702425e78a4257800935880c446f..6b067675944f70832f3c3647a5a89ca10136bd61 100644 (file)
@@ -110,25 +110,24 @@ addrtostr6 (const void *src, char *dst, size_t size)
   size_t space_left, added_space;
   int snprintfed;
   struct {
-    long base;
-    long len;
+    int base;
+    int len;
   } best, cur;
-  u_long words [IN6ADDRSZ / INT16SZ];
-  u_int  i;
+  uint16_t words [IN6ADDRSZ / INT16SZ];
+  int  i;
 
   /* Preprocess:
    *  Copy the input (bytewise) array into a wordwise array.
    *  Find the longest run of 0x00's in src[] for :: shorthanding.
    */
-  memset (words, 0, sizeof(words));
-  for (i = 0; i < IN6ADDRSZ; i++)
-      words[i/2] |= (srcaddr[i] << ((1 - (i % 2)) << 3));
+  for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
+      words[i] = (srcaddr[2*i] << 8) | srcaddr[2*i + 1];
 
   best.len = 0;
   best.base = -1;
   cur.len = 0;
   cur.base  = -1;
-  for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
+  for (i = 0; i < (int)(IN6ADDRSZ / INT16SZ); i++)
   {
     if (words[i] == 0)
     {
@@ -161,7 +160,7 @@ addrtostr6 (const void *src, char *dst, size_t size)
         *dp++ = c; \
         space_left--; \
     }
-  for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
+  for (i = 0; i < (int)(IN6ADDRSZ / INT16SZ); i++)
   {
     /* Are we inside the best run of 0x00's?
      */
@@ -192,7 +191,7 @@ addrtostr6 (const void *src, char *dst, size_t size)
       space_left -= added_space;
       break;
     }
-    snprintfed = snprintf (dp, space_left, "%lx", words[i]);
+    snprintfed = snprintf (dp, space_left, "%x", words[i]);
     if (snprintfed < 0)
         return (NULL);
     if ((size_t) snprintfed >= space_left)