diff options
Diffstat (limited to 'lib/src/common.h')
-rw-r--r-- | lib/src/common.h | 30 |
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 */ /* |