Fix various aliasing violations

This allows the code to be built even with
-fstrict-aliasing -Werror=strict-aliasing -Wstrict-aliasing=2

Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
Cc: patches@linaro.org
diff --git a/native/libMicro-0.4.0/close_tcp.c b/native/libMicro-0.4.0/close_tcp.c
index 6bce7a7..3798ec1 100644
--- a/native/libMicro-0.4.0/close_tcp.c
+++ b/native/libMicro-0.4.0/close_tcp.c
@@ -157,7 +157,10 @@
 	tsd_t			*ts = (tsd_t *)tsd;
 	int			i;
 	int			result;
-	struct sockaddr_in	addr;
+	union {
+		struct sockaddr_in	in;
+		struct sockaddr 	sa;
+	} addr;
 	socklen_t		size;
 	int			errors = 0;
 
@@ -175,8 +178,14 @@
 			continue;
 		}
 
+		union {
+			struct sockaddr *sa;
+			struct sockaddr_in *in;
+		} ts_add;
+		ts_add.in = &ts->ts_adds[i];
+
 		result = connect(ts->ts_cons[i],
-		    (struct sockaddr *)&ts->ts_adds[i],
+		    ts_add.sa,
 		    sizeof (struct sockaddr_in));
 
 		if ((result == -1) && (errno != EINPROGRESS)) {
@@ -186,7 +195,7 @@
 		}
 
 		size = sizeof (struct sockaddr);
-		result = accept(ts->ts_lsns[i], (struct sockaddr *)&addr,
+		result = accept(ts->ts_lsns[i], &addr.sa,
 		    &size);
 		if (result == -1) {
 			perror("accept");
diff --git a/native/libMicro-0.4.0/connection.c b/native/libMicro-0.4.0/connection.c
index 67239f9..d515a0c 100644
--- a/native/libMicro-0.4.0/connection.c
+++ b/native/libMicro-0.4.0/connection.c
@@ -233,7 +233,7 @@
 	tsd_t			*ts = (tsd_t *)tsd;
 	int			i;
 	int			result;
-	struct sockaddr_in	addr;
+	struct sockaddr		addr;
 	socklen_t		size;
 
 	for (i = 0; i < lm_optB; i++) {
diff --git a/native/libMicro-0.4.0/getpeername.c b/native/libMicro-0.4.0/getpeername.c
index 877215d..3699b79 100644
--- a/native/libMicro-0.4.0/getpeername.c
+++ b/native/libMicro-0.4.0/getpeername.c
@@ -69,7 +69,10 @@
 	int			result;
 	socklen_t		size;
 	struct hostent	*host;
-	struct sockaddr_in	adds;
+	union {
+		struct sockaddr_in in;
+		struct sockaddr	sa;
+	} adds;
 	int			sock2, sock3;
 
 	sock2 = socket(AF_INET, SOCK_STREAM, 0);
@@ -92,12 +95,12 @@
 	j = FIRSTPORT;
 	for (;;) {
 		(void) memset(&adds, 0, sizeof (struct sockaddr_in));
-		adds.sin_family = AF_INET;
-		adds.sin_port = htons(j++);
-		(void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0],
+		adds.in.sin_family = AF_INET;
+		adds.in.sin_port = htons(j++);
+		(void) memcpy(&adds.in.sin_addr.s_addr, host->h_addr_list[0],
 		    sizeof (struct in_addr));
 
-		if (bind(sock2, (struct sockaddr *)&adds,
+		if (bind(sock2, &adds.sa,
 		    sizeof (struct sockaddr_in)) == 0) {
 			break;
 		}
@@ -124,7 +127,7 @@
 		exit(1);
 	}
 
-	result = connect(sock3, (struct sockaddr *)&adds,
+	result = connect(sock3, &adds.sa,
 	    sizeof (struct sockaddr_in));
 	if ((result == -1) && (errno != EINPROGRESS)) {
 		perror("connect");
@@ -132,7 +135,7 @@
 	}
 
 	size = sizeof (struct sockaddr);
-	sock = accept(sock2, (struct sockaddr *)&adds, &size);
+	sock = accept(sock2, &adds.sa, &size);
 	if (sock == -1) {
 		perror("accept");
 		exit(1);
@@ -146,7 +149,7 @@
 benchmark(void *tsd, result_t *res)
 {
 	int			i;
-	struct sockaddr_in	adds;
+	struct sockaddr		adds;
 	socklen_t		size;
 
 	for (i = 0; i < lm_optB; i++) {
diff --git a/native/libMicro-0.4.0/getsockname.c b/native/libMicro-0.4.0/getsockname.c
index e3f7769..1e7820b 100644
--- a/native/libMicro-0.4.0/getsockname.c
+++ b/native/libMicro-0.4.0/getsockname.c
@@ -86,13 +86,18 @@
 
 	j = FIRSTPORT;
 	for (;;) {
-		(void) memset(&adds, 0, sizeof (struct sockaddr_in));
-		adds.sin_family = AF_INET;
-		adds.sin_port = htons(j++);
-		(void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0],
+		union {
+			struct sockaddr_in *in;
+			struct sockaddr *sa;
+		} ad;
+		ad.in = &adds;
+		(void) memset(ad.in, 0, sizeof (struct sockaddr_in));
+		ad.in->sin_family = AF_INET;
+		ad.in->sin_port = htons(j++);
+		(void) memcpy(&ad.in->sin_addr.s_addr, host->h_addr_list[0],
 		    sizeof (struct in_addr));
 
-		if (bind(sock, (struct sockaddr *)&adds,
+		if (bind(sock, ad.sa,
 		    sizeof (struct sockaddr_in)) == 0) {
 			break;
 		}
@@ -111,7 +116,7 @@
 benchmark(void *tsd, result_t *res)
 {
 	int			i;
-	struct sockaddr_in	adds;
+	struct sockaddr		adds;
 	socklen_t		size;
 
 	for (i = 0; i < lm_optB; i++) {
diff --git a/native/libMicro-0.4.0/libmicro.c b/native/libMicro-0.4.0/libmicro.c
index b4e11c2..d929f00 100644
--- a/native/libMicro-0.4.0/libmicro.c
+++ b/native/libMicro-0.4.0/libmicro.c
@@ -176,10 +176,13 @@
     int flag = 1;
     setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));  
 
-    struct sockaddr_in servername;
+    union {
+        struct sockaddr_in servername;
+        struct sockaddr servername_g;
+    } sa;
     /* Connect to the server. */
-    init_sockaddr (&servername, SERVERHOST, PORT);
-    if ( 0 > connect(sock, (struct sockaddr *) &servername, sizeof (servername)) ) {
+    init_sockaddr (&sa.servername, SERVERHOST, PORT);
+    if ( 0 > connect(sock, &sa.servername_g, sizeof (sa.servername)) ) {
         fprintf (stderr, "cannot connect to server.");
         fflush(stderr);
         exit (EXIT_FAILURE);
diff --git a/native/libMicro-0.4.0/listen.c b/native/libMicro-0.4.0/listen.c
index f8730d7..9e2811b 100644
--- a/native/libMicro-0.4.0/listen.c
+++ b/native/libMicro-0.4.0/listen.c
@@ -89,13 +89,18 @@
 
 	j = FIRSTPORT;
 	for (;;) {
-		(void) memset(&adds, 0, sizeof (struct sockaddr_in));
-		adds.sin_family = AF_INET;
-		adds.sin_port = htons(j++);
-		(void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0],
+		union {
+			struct sockaddr_in *in;
+			struct sockaddr *sa;
+		} ad;
+		ad.in = &adds;
+		(void) memset(&ad.in, 0, sizeof (struct sockaddr_in));
+		ad.in->sin_family = AF_INET;
+		ad.in->sin_port = htons(j++);
+		(void) memcpy(&ad.in->sin_addr.s_addr, host->h_addr_list[0],
 		    sizeof (struct in_addr));
 
-		if (bind(sock, (struct sockaddr *)&adds,
+		if (bind(sock, ad.sa,
 		    sizeof (struct sockaddr_in)) == 0) {
 			break;
 		}
diff --git a/native/libMicro-0.4.0/pipe.c b/native/libMicro-0.4.0/pipe.c
index e873d9f..04e3064 100644
--- a/native/libMicro-0.4.0/pipe.c
+++ b/native/libMicro-0.4.0/pipe.c
@@ -338,6 +338,11 @@
 	int			j;
 	int			opt = 1;
 	struct hostent	*host;
+	union {
+		struct sockaddr_in	*in;
+		struct sockaddr		*sa;
+	} tsad;
+	tsad.in = &ts->ts_add;
 
 	j = FIRSTPORT;
 
@@ -358,13 +363,13 @@
 	for (;;) {
 		(void) memset(&ts->ts_add, 0,
 		    sizeof (struct sockaddr_in));
-		ts->ts_add.sin_family = AF_INET;
-		ts->ts_add.sin_port = htons(j++);
-		(void) memcpy(&ts->ts_add.sin_addr.s_addr,
+		tsad.in->sin_family = AF_INET;
+		tsad.in->sin_port = htons(j++);
+		(void) memcpy(&tsad.in->sin_addr.s_addr,
 		    host->h_addr_list[0], sizeof (struct in_addr));
 
 		if (bind(ts->ts_lsn,
-		    (struct sockaddr *)&ts->ts_add,
+		    tsad.sa,
 		    sizeof (struct sockaddr_in)) == 0) {
 			break;
 		}
@@ -385,10 +390,16 @@
 prepare_localtcp(tsd_t *ts)
 {
 	int			result;
-	struct sockaddr_in	addr;
+	struct sockaddr		addr;
 	int			opt = 1;
 	socklen_t		size;
 
+	union {
+		struct sockaddr_in *in;
+		struct sockaddr *sa;
+	} tsad;
+	tsad.in = &ts->ts_add;
+
 	if (ts->ts_once++ == 0) {
 		if (prepare_localtcp_once(ts) == -1) {
 			return (-1);
@@ -404,7 +415,7 @@
 		return (-1);
 	}
 
-	result = connect(ts->ts_out, (struct sockaddr *)&ts->ts_add,
+	result = connect(ts->ts_out, tsad.sa,
 	    sizeof (struct sockaddr_in));
 	if ((result == -1) && (errno != EINPROGRESS)) {
 		return (-1);
diff --git a/native/unixbench-5.1.2/src/socket.c b/native/unixbench-5.1.2/src/socket.c
index 69a4bd3..bb1d1f2 100644
--- a/native/unixbench-5.1.2/src/socket.c
+++ b/native/unixbench-5.1.2/src/socket.c
@@ -39,10 +39,13 @@
     int flag = 1;
     setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));  
 
-    struct sockaddr_in servername;
+    union {
+        struct sockaddr_in in;
+        struct sockaddr sa;
+    } servername;
     /* Connect to the server. */
-    init_sockaddr (&servername, SERVERHOST, PORT);
-    if ( 0 > connect(sock, (struct sockaddr *) &servername, sizeof (servername)) ) {
+    init_sockaddr (&servername.in, SERVERHOST, PORT);
+    if ( 0 > connect(sock, &servername.sa, sizeof (servername)) ) {
         fprintf (stderr, "cannot connect to server.");
         fflush(stderr);
         exit (EXIT_FAILURE);