Project

General

Profile

Actions

Bug #1053

closed

master-2013-12-02: util-byte.h: Solaris doesn't have swap16/32/64

Added by Mark Solaris over 10 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Affected Versions:
Effort:
Difficulty:
Label:

Description

Requires OS_SOLARIS definition from https://redmine.openinfosecfoundation.org/issues/1051

Checking for i86/SPARC:

--- util-byte.h.orig    2013-12-03 14:31:30.327775209 +1100
+++ util-byte.h 2013-12-03 14:42:09.574001791 +1100
@@ -64,6 +64,34 @@
        | (((x) & 0x0000000000ff0000ull) << 24)     \
        | (((x) & 0x000000000000ff00ull) << 40)     \
        | (((x) & 0x00000000000000ffull) << 56))
+#elif OS_SOLARIS
+#    define bswap_8(x)      ((x) & 0xff)
+#    if !defined(__i386) && !defined(__amd64)
+#        define SCByteSwap16(x) ((bswap_8(x) << 8) | bswap_8((x) >> 8))
+#        define SCByteSwap32(x) (((uint32_t)(x) << 24) | \
+                                (((uint32_t)(x) << 8) & 0xff0000) | \
+                                (((uint32_t)(x) >> 8) & 0xff00) | \
+                                ((uint32_t)(x)  >> 24))
+#    else /* x86 */
+#        define SCByteSwap16(x) htons(x)
+#        define SCByteSwap32(x) htonl(x)
+#    endif  /* !__i386 && !__amd64 */
+#    if defined(_LP64) || defined(_LONGLONG_TYPE)
+#        if (!defined(__i386) && !defined(__amd64))
+#            define SCByteSwap64(x) (((uint64_t)(x) << 56) | \
+                                    (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
+                                    (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
+                                    (((uint64_t)(x) << 8)  & 0xff00000000ULL) | \
+                                    (((uint64_t)(x) >> 8)  & 0xff000000ULL) | \
+                                    (((uint64_t)(x) >> 24) & 0xff0000ULL) | \
+                                    (((uint64_t)(x) >> 40) & 0xff00ULL) | \
+                                    ((uint64_t)(x)  >> 56))
+#        else /* x86 */
+#            define SCByteSwap64(x) htonll(x)
+#        endif  /* !__i386 && !__amd64 */
+#    else /* no uint64_t */
+#        define SCByteSwap64(x)     ((SCByteSwap32(x) << 32) | SCByteSwap32((x) >> 32))
+#    endif
 #else
 #include <byteswap.h>
 #define SCByteSwap16(x) bswap_16(x)
Actions #1

Updated by Andreas Herz over 8 years ago

  • Status changed from New to Closed
Actions

Also available in: Atom PDF