From 78efb846abafda30ede9a87a51c3c988a20d6d63 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 18 Jul 2014 13:36:59 +0000 Subject: [PATCH] changed byteorder of message data (now big endian => network byte order) git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@162 8ec27952-4edc-4aab-86aa-e87bb2611832 --- .../opal/models/send_receive/src/AsyncIP.c | 8 +++---- clients/opal/models/send_receive/src/Utils.c | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 clients/opal/models/send_receive/src/Utils.c diff --git a/clients/opal/models/send_receive/src/AsyncIP.c b/clients/opal/models/send_receive/src/AsyncIP.c index fb26aeaa6..a99368cc3 100644 --- a/clients/opal/models/send_receive/src/AsyncIP.c +++ b/clients/opal/models/send_receive/src/AsyncIP.c @@ -101,8 +101,8 @@ static void *SendToIPPort(void *arg) msg.length = mdldata_size / sizeof(double); for (i = 0; i < msg.length; i++) - msg.data[i] = (float) mdldata[i]; - + msg.data[i] = htonf((float) mdldata[i]); + msg_size = 4 * (msg.length + 1); /**********************************************************************/ @@ -209,7 +209,7 @@ static void *RecvFromIPPort(void *arg) } for (i = 0; i < msg.length; i++) - mdldata[i] = (double) msg.data[i]; + mdldata[i] = (double) ntohf(msg.data[i]); /************************************************************************/ OpalSetAsyncRecvIconData(mdldata, mdldata_size, RecvID); @@ -236,7 +236,7 @@ int main(int argc, char *argv[]) pthread_t tid_send, tid_recv; pthread_attr_t attr_send, attr_recv; - + OpalPrint("%s: This is a S2SS client\n", PROGNAME); /* Check for the proper arguments to the program */ diff --git a/clients/opal/models/send_receive/src/Utils.c b/clients/opal/models/send_receive/src/Utils.c new file mode 100644 index 000000000..f88ce7e56 --- /dev/null +++ b/clients/opal/models/send_receive/src/Utils.c @@ -0,0 +1,23 @@ + +static union fi { + float f; + uint32_t i; +}; + +inline float ntohf(float flt) +{ + union fi u = { .f = flt }; + + u.i = ntohl(u.i); + + return u.f; +} + +inline float htonf(float flt) +{ + union u = { .f = flt }; + + u.i = htonl(u.i); + + return u.f; +}