aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouni Malinen <jouni.malinen@atheros.com>2009-11-05 10:11:49 (GMT)
committerJouni Malinen <j@w1.fi>2009-11-22 18:13:27 (GMT)
commit85accf1d2a5b7b9baa5bd5830dff3621b2a2a0c8 (patch)
treef48768571606f3eb64ff9dda00aa0804d3b79480
parent3b8845ee6db5d1b3e5fed45fc739cb3851646bdd (diff)
downloadhostap-06-85accf1d2a5b7b9baa5bd5830dff3621b2a2a0c8.zip
hostap-06-85accf1d2a5b7b9baa5bd5830dff3621b2a2a0c8.tar.gz
hostap-06-85accf1d2a5b7b9baa5bd5830dff3621b2a2a0c8.tar.bz2
Use type-punning to avoid breaking strict aliasing rules
While the actual use here would be unlikely to be broken by any C optimization, it is better to use explicit union construction to let gcc know about the aliasing and avoid warnings from gcc 4.4. (cherry picked from commit 5a641ae01e9d9040cf838b6c40dbda1b8c724aba)
-rw-r--r--src/radius/radius_server.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/radius/radius_server.c b/src/radius/radius_server.c
index 1bfb93c..cb4d7b1 100644
--- a/src/radius/radius_server.c
+++ b/src/radius/radius_server.c
@@ -663,7 +663,13 @@ static void radius_server_receive_auth(int sock, void *eloop_ctx,
{
struct radius_server_data *data = eloop_ctx;
u8 *buf = NULL;
- struct sockaddr_storage from;
+ union {
+ struct sockaddr_storage ss;
+ struct sockaddr_in sin;
+#ifdef CONFIG_IPV6
+ struct sockaddr_in6 sin6;
+#endif /* CONFIG_IPV6 */
+ } from;
socklen_t fromlen;
int len;
struct radius_client *client = NULL;
@@ -678,7 +684,7 @@ static void radius_server_receive_auth(int sock, void *eloop_ctx,
fromlen = sizeof(from);
len = recvfrom(sock, buf, RADIUS_MAX_MSG_LEN, 0,
- (struct sockaddr *) &from, &fromlen);
+ (struct sockaddr *) &from.ss, &fromlen);
if (len < 0) {
perror("recvfrom[radius_server]");
goto fail;
@@ -686,28 +692,26 @@ static void radius_server_receive_auth(int sock, void *eloop_ctx,
#ifdef CONFIG_IPV6
if (data->ipv6) {
- struct sockaddr_in6 *from6 = (struct sockaddr_in6 *) &from;
- if (inet_ntop(AF_INET6, &from6->sin6_addr, abuf, sizeof(abuf))
- == NULL)
+ if (inet_ntop(AF_INET6, &from.sin6.sin6_addr, abuf,
+ sizeof(abuf)) == NULL)
abuf[0] = '\0';
- from_port = ntohs(from6->sin6_port);
+ from_port = ntohs(from.sin6.sin6_port);
RADIUS_DEBUG("Received %d bytes from %s:%d",
len, abuf, from_port);
client = radius_server_get_client(data,
(struct in_addr *)
- &from6->sin6_addr, 1);
+ &from.sin6.sin6_addr, 1);
}
#endif /* CONFIG_IPV6 */
if (!data->ipv6) {
- struct sockaddr_in *from4 = (struct sockaddr_in *) &from;
- os_strlcpy(abuf, inet_ntoa(from4->sin_addr), sizeof(abuf));
- from_port = ntohs(from4->sin_port);
+ os_strlcpy(abuf, inet_ntoa(from.sin.sin_addr), sizeof(abuf));
+ from_port = ntohs(from.sin.sin_port);
RADIUS_DEBUG("Received %d bytes from %s:%d",
len, abuf, from_port);
- client = radius_server_get_client(data, &from4->sin_addr, 0);
+ client = radius_server_get_client(data, &from.sin.sin_addr, 0);
}
RADIUS_DUMP("Received data", buf, len);