+2005-09-07 Roland Dreier <roland@cisco.com>
+
+ * src/device.c (ibv_get_device_guid): Use htonll() instead of
+ relying on pointer aliasing (which seems to break for some gcc
+ versions).
+
+ * include/infiniband/arch.h: Add htonll() and ntohll() functions.
+
2005-09-06 Roland Dreier <roland@cisco.com>
* include/infiniband/kern-abi.h, include/infiniband/verbs.h,
#ifndef INFINIBAND_ARCH_H
#define INFINIBAND_ARCH_H
+#include <endian.h>
+#include <byteswap.h>
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+static inline uint64_t htonll(uint64_t x) { return bswap_64(x); }
+static inline uint64_t ntohll(uint64_t x) { return bswap_64(x); }
+#elif __BYTE_ORDER == __BIG_ENDIAN
+static inline uint64_t htonll(uint64_t x) { return x; }
+static inline uint64_t ntohll(uint64_t x) { return x; }
+#endif
+
/*
* Architecture-specific defines. Currently, an architecture is
* required to implement the following operations:
#include <unistd.h>
#include <alloca.h>
+#include <infiniband/arch.h>
+
#include "ibverbs.h"
static struct dlist *device_list;
uint64_t ibv_get_device_guid(struct ibv_device *device)
{
struct sysfs_attribute *attr;
- uint16_t guid[4];
+ uint64_t guid = 0;
+ uint16_t parts[4];
int i;
attr = sysfs_get_classdev_attr(device->ibdev, "node_guid");
return 0;
if (sscanf(attr->value, "%hx:%hx:%hx:%hx",
- guid, guid + 1, guid + 2, guid + 3) != 4)
+ parts, parts + 1, parts + 2, parts + 3) != 4)
return 0;
for (i = 0; i < 4; ++i)
- guid[i] = htons(guid[i]);
+ guid = (guid << 16) | parts[i];
- return *(uint64_t *) guid;
+ return htonll(guid);
}
struct ibv_context *ibv_open_device(struct ibv_device *device)