summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2014-04-12 10:40:08 +0200
committerPatrick McHardy <kaber@trash.net>2014-04-12 10:55:26 +0200
commite4645012a69a36588886c6af87fb5a2b49834869 (patch)
tree8c0b3957a181184c90b0e6ca3cd432178d95d08e
parent5259feeb7cda089523a2196248baa5395bce4b50 (diff)
gmputil: use MSF/LSF in import/export functions dependant on host byte order
For data of byteorder BYTEORDER_HOST_ENDIAN we need to set the word order dependant on the host byte order. Signed-off-by: Patrick McHardy <kaber@trash.net>
-rw-r--r--include/gmputil.h9
-rw-r--r--src/gmputil.c7
2 files changed, 14 insertions, 2 deletions
diff --git a/include/gmputil.h b/include/gmputil.h
index 88be697a..63eb0ba9 100644
--- a/include/gmputil.h
+++ b/include/gmputil.h
@@ -2,12 +2,21 @@
#define NFTABLES_GMPUTIL_H
#include <gmp.h>
+#include <asm/byteorder.h>
enum mpz_word_order {
MPZ_MSWF = 1,
MPZ_LSWF = -1,
};
+#ifdef __LITTLE_ENDIAN_BITFIELD
+#define MPZ_HWO MPZ_LSWF
+#elif defined(__BIG_ENDIAN_BITFIELD)
+#define MPZ_HWO MPZ_MSWF
+#else
+#error "byteorder undefined"
+#endif
+
enum mpz_byte_order {
MPZ_BIG_ENDIAN = 1,
MPZ_HOST_ENDIAN = 0,
diff --git a/src/gmputil.c b/src/gmputil.c
index f34c077e..cb464457 100644
--- a/src/gmputil.c
+++ b/src/gmputil.c
@@ -98,20 +98,23 @@ void *mpz_export_data(void *data, const mpz_t op,
enum byteorder byteorder,
unsigned int len)
{
+ enum mpz_word_order order;
enum mpz_byte_order endian;
switch (byteorder) {
case BYTEORDER_BIG_ENDIAN:
default:
+ order = MPZ_MSWF;
endian = MPZ_BIG_ENDIAN;
break;
case BYTEORDER_HOST_ENDIAN:
+ order = MPZ_HWO;
endian = MPZ_HOST_ENDIAN;
break;
}
memset(data, 0, len);
- mpz_export(data, NULL, MPZ_MSWF, len, endian, 0, op);
+ mpz_export(data, NULL, order, len, endian, 0, op);
return data;
}
@@ -129,7 +132,7 @@ void mpz_import_data(mpz_t rop, const void *data,
endian = MPZ_BIG_ENDIAN;
break;
case BYTEORDER_HOST_ENDIAN:
- order = MPZ_LSWF;
+ order = MPZ_HWO;
endian = MPZ_HOST_ENDIAN;
break;
}