aboutsummaryrefslogtreecommitdiffstats
path: root/lib/src/common.h
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-02-11 23:50:45 +0100
committerMauro Sardara <msardara@cisco.com>2019-02-12 13:15:47 +0000
commitfbd4dd9c5eba6f8f10bcc0db30a72ea3378c149b (patch)
treee65187748120c945e39256084d5614ed127b8383 /lib/src/common.h
parentf126f86da5acf088f24e97ecb32f9ba5a1789aa4 (diff)
[HICN-51] Add static assert for ensuring correct struct size in libhicn definitions.
Change-Id: Ib41e9cbdd2ea84a40eb4e7b01da131cbad9575c4 Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'lib/src/common.h')
-rw-r--r--lib/src/common.h30
1 files changed, 25 insertions, 5 deletions
diff --git a/lib/src/common.h b/lib/src/common.h
index e67762301..1d4b1e6bf 100644
--- a/lib/src/common.h
+++ b/lib/src/common.h
@@ -80,7 +80,7 @@ typedef uint8_t u8;
#define __ORDER_BIG_ENDIAN__ 0x44434241UL
#define __BYTE_ORDER__ ('ABCD')
- /* Windows compatibility headers*/
+ /* Windows compatibility headers */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
@@ -95,14 +95,22 @@ typedef uint8_t u8;
#define IOVEC
#define UIO_MAXIOV 16
#define IOV_MAX UIO_MAXIOV
-struct iovec {
- void* iov_base;
- size_t iov_len;
+struct iovec
+{
+ void *iov_base;
+ size_t iov_len;
};
#endif
-
#endif
+/*
+ * Portable attribute packed.
+ */
+#ifndef _WIN32
+#define PACKED( __Declaration__ ) __Declaration__ __attribute__((__packed__))
+#else
+#define PACKED( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
+#endif
/*
@@ -120,6 +128,7 @@ struct iovec {
#ifndef _WIN32
#include <netinet/in.h>
#endif
+
typedef union
{
u32 as_u32;
@@ -265,6 +274,17 @@ csum (const void *addr, size_t size, u16 init)
*/
#define HICN_IP_VERSION(packet) ((hicn_header_t *)packet)->v4.ip.version
+/*
+ * ntohll / htonll allows byte swapping for 64 bits integers
+ */
+#ifndef htonll
+#define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
+#endif
+
+#ifndef ntohll
+#define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
+#endif
+
#endif /* HICN_COMMON_H */
/*