Skip to content

Conversation

@ravd
Copy link

@ravd ravd commented Nov 26, 2024

No description provided.

@sflow
Copy link
Owner

sflow commented Jan 6, 2025

I don't have the Xcode build tools installed on my Mac, but I think the right way to do this it to edit configure.ac and add byteswap.h to the AC_CHECK_HEADERS list. That will cause HAVE_BYTESWAP_H to be set to 1 or 0 in config.h when you rebuild. And then you can do something like this in sflowtool.c:

#if HAVE_BYTESWAP_H
#include <byteswap.h>
#else
#define bswap_16 __builtin_bswap_16
#define bswap_32 __builtin_bswap_32
#define bswap_64 __builtin_bswap_64
#endif

Or use the code you suggested if those builtins do not exist (I didn't check any of this).

Having said all that, I suggest you just run sflowtool under docker. It's more likely to work as expected, and the overhead is small. Just try this:

docker run sflowtool

@sflow
Copy link
Owner

sflow commented Jan 29, 2025

I finally got around to trying this properly, and of course I learned that _builtin_bswap* is not known to the compiler on macOS. So the latest sflowtool.c includes something closer to what was proposed. Please review when you have time. It looks like this:

#if HAVE_BYTESWAP_H
#include <byteswap.h>
#else
#define bswap_16(value)
((((value) & 0xff) << 8) | ((value) >> 8))

#define bswap_32(value)
(((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) |
(uint32_t)bswap_16((uint16_t)((value) >> 16)))

#define bswap_64(value)
(((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) << 32) |
(uint64_t)bswap_32((uint32_t)((value) >> 32)))
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants