Actions
Bug #865
closed1.4.3: src/util-print.c: Solaris doesn't have a s6_addr16
Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Affected Versions:
Effort:
Difficulty:
Label:
Description
Solaris doesn't define s6_addr16 in the in6_addr struct. We need to work around that.
One interesting fix is used by the tor project:
https://svn.torproject.org/svn/tor/branches/tor-0_2_0-patches/src/common/compat.h
/* Apparently, MS and Solaris don't define s6_addr16 or s6_addr32. */ #ifdef HAVE_STRUCT_IN6_ADDR_S6_ADDR32 #define S6_ADDR32(x) ((uint32_t*)(x).s6_addr32) #else #define S6_ADDR32(x) ((uint32_t*)((char*)&(x).s6_addr)) #endif #ifdef HAVE_STRUCT_IN6_ADDR_S6_ADDR16 #define S6_ADDR16(x) ((uint16_t*)(x).s6_addr16) #else #define S6_ADDR16(x) ((uint16_t*)((char*)&(x).s6_addr)) #endif
I'm not sure I enjoy reading that so I've elected to go a more portable approach, double stepping through 16 * s6_addr8 instead of 8 * s6_addr16
What a simplified in6_addr struct looks like:
struct in6_addr {
union {
uint8_t u6_addr8[16];
uint16_t u6_addr16[8];
uint32_t u6_addr32[4];
} in6_u;
#define s6_addr in6_u.u6_addr8
#define s6_addr16 in6_u.u6_addr16
#define s6_addr32 in6_u.u6_addr32
};
Using that we can replicate what s6_addr16 does:
--- suricata-1.4.3/src/util-print.c.orig Tue Jul 9 19:24:32 2013
+++ suricata-1.4.3/src/util-print.c Tue Jul 9 19:25:03 2013
@@ -217,8 +217,8 @@
return;
}
-#ifndef s6_addr16
-# define s6_addr16 __u6_addr.__u6_addr16
+#if !defined(s6_addr16) && !defined(__sun)
+# define s6_addr16 __u6_addr.__u6_addr16
#endif
static const char *PrintInetIPv6(const void *src, char *dst, socklen_t size)
@@ -225,6 +225,9 @@
{
struct in6_addr * insrc = (struct in6_addr *) src;
int i;
+#if defined(__sun)
+ int sol_loc;
+#endif
char s_part[6];
/* current IPv6 format is fixed size */
@@ -234,7 +237,12 @@
}
memset(dst, 0, size);
for(i = 0; i < 8; i++) {
+#if defined(__sun) /* Step through in different units as we don't have the non-standard s6_addr16 */
+ sol_loc = (i * 2); /* We use _S6_un._S6_u8 so we need to double step the pointer */
+ snprintf(s_part, 6, "%04x:", htons((uint16_t)insrc->s6_addr[sol_loc]));
+#else
snprintf(s_part, 6, "%04x:", htons(insrc->s6_addr16[i]));
+#endif
strlcat(dst, s_part, size);
}
/* suppress last ':' */
Actions