From 4e3e77eb13bf531bfd657f28c9fa89a37407cfc9 Mon Sep 17 00:00:00 2001 From: Steven Dake Date: Tue, 4 Aug 2009 00:04:13 +0000 Subject: [PATCH] Always keep autogenerated node ids in totem as LE even on BE arches. Have testcpg print out autogenerated nodeid properly on BE arch. git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2377 fd59a12c-fef9-0310-b244-a6a79926bd2f --- exec/totemip.c | 6 +++++ test/testcpg.c | 72 ++++++++++++++++++++------------------------------ 2 files changed, 35 insertions(+), 43 deletions(-) diff --git a/exec/totemip.c b/exec/totemip.c index caf78d15..20dc940f 100644 --- a/exec/totemip.c +++ b/exec/totemip.c @@ -376,6 +376,9 @@ int totemip_iface_check(struct totem_ip_address *bindnet, */ totemip_sockaddr_to_totemip_convert((struct sockaddr_storage *)sockaddr_in, boundto); boundto->nodeid = sockaddr_in->sin_addr.s_addr; +#if __BYTE_ORDER == __BIG_ENDIAN + boundto->nodeid = swab32 (boundto->nodeid); +#endif if (ioctl(id_fd, SIOCGLIFFLAGS, &lifreq[i]) < 0) { printf ("couldn't do ioctl\n"); @@ -614,6 +617,9 @@ finished: if (ipaddr.family == AF_INET && ipaddr.nodeid == 0) { unsigned int nodeid = 0; memcpy (&nodeid, ipaddr.addr, sizeof (int)); +#if __BYTE_ORDER == __BIG_ENDIAN + nodeid = swab32 (nodeid); +#endif if (mask_high_bit) { nodeid &= 0x7FFFFFFF; } diff --git a/test/testcpg.c b/test/testcpg.c index 24154349..c9fe79d3 100644 --- a/test/testcpg.c +++ b/test/testcpg.c @@ -48,6 +48,7 @@ #include #include +#include static int quit = 0; static int show_ip = 0; @@ -61,6 +62,24 @@ static void print_cpgname (const struct cpg_name *name) } } +static char * node_pid_format(unsigned int nodeid,int pid) { + static char buffer[100]; + if (show_ip) { + struct in_addr saddr; +#if __BYTE_ORDER == __BIG_ENDIAN + saddr.s_addr = swab32(nodeid); +#else + saddr.s_addr = nodeid; +#endif + sprintf(buffer, "node/pid %s/%d", inet_ntoa(saddr),pid); + } + else { + sprintf(buffer, "node/pid %d/%d", nodeid, pid); + } + return buffer; +} + + static void DeliverCallback ( cpg_handle_t handle, const struct cpg_name *groupName, @@ -69,18 +88,9 @@ static void DeliverCallback ( void *msg, size_t msg_len) { - if (show_ip) { - struct in_addr saddr; - saddr.s_addr = nodeid; - printf("DeliverCallback: message (len=%lu)from node/pid %s/%d: '%s'\n", - (unsigned long int) msg_len, - inet_ntoa(saddr), pid, (const char *)msg); - } - else { - printf("DeliverCallback: message (len=%lu)from node/pid %d/%d: '%s'\n", - (unsigned long int) msg_len, nodeid, pid, + printf("DeliverCallback: message (len=%lu)from %s: '%s'\n", + (unsigned long int) msg_len, node_pid_format(nodeid, pid), (const char *)msg); - } } static void ConfchgCallback ( @@ -91,51 +101,27 @@ static void ConfchgCallback ( const struct cpg_address *joined_list, size_t joined_list_entries) { int i; - struct in_addr saddr; printf("\nConfchgCallback: group '"); print_cpgname(groupName); printf("'\n"); for (i=0; i