]> The Tcpdump Group git mirrors - tcpdump/commitdiff
fix missing/inet_ntop.c again
authorGisle Vanem <[email protected]>
Thu, 1 May 2014 10:39:17 +0000 (14:39 +0400)
committerDenis Ovsienko <[email protected]>
Thu, 1 May 2014 10:39:17 +0000 (14:39 +0400)
All tests that should print IPv6-addresses failed since 'INET6' wasn't
set when my missing/inet_ntop.c was compiled. Due to "config.h" was not
included.

Also got rid of 2 warnings:
 Missing/inet_ntop.c:146:23: warning: 'cur.len' may be used
 uninitialized in this function [-Wmaybe-uninitialized]

The tests also failed since the inet_ntop_v6() was returning hex-chars
in upper-case. So this patch returns string in lower-case.

missing/inet_ntop.c

index 87ab7bb61535a1856e5e9d6c9de28ed4f9d02213..57539dc5ce80beed97d2d5707a3ad08c158d1efd 100644 (file)
  * SUCH DAMAGE.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <tcpdump-stdinc.h>
 
 #include <stdio.h>
@@ -119,7 +123,9 @@ inet_ntop_v6 (const u_char *src, char *dst, size_t size)
   for (i = 0; i < IN6ADDRSZ; i++)
       words[i/2] |= (src[i] << ((1 - (i % 2)) << 3));
 
+  best.len = 0;
   best.base = -1;
+  cur.len = 0;
   cur.base  = -1;
   for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++)
   {
@@ -173,7 +179,7 @@ inet_ntop_v6 (const u_char *src, char *dst, size_t size)
       tp += strlen(tp);
       break;
     }
-    tp += sprintf (tp, "%lX", words[i]);
+    tp += sprintf (tp, "%lx", words[i]);
   }
 
   /* Was it a trailing run of 0x00's?