Commit 2a7b3c9a authored by Pekka Pessi's avatar Pekka Pessi

Fixed msg_addrlen() usage.

msg_addrlen() returns a pointer to ai_addrlen field of struct addrinfo
inside the msg_t object. ai_addrlen has type size_t. However, system calls
taking a return valur pointer to address length, use type socklen_t.
Typically size_t is unsigned long, socklen_t is int, so casting
msg_addrlen() return value to (socklen_t *) will break on (high-endian)
64-bit platforms. svsp.

darcs-hash:20060512123739-65a35-f40e2a77be00bd3293d8cc6877252b046afabcce.gz
parent 39b86fb3
......@@ -145,7 +145,8 @@ static int addr_test(void)
{
BEGIN();
TEST(sizeof(socklen_t), sizeof(size_t));
/* It *will* fail. */
/* TEST(sizeof(socklen_t), sizeof(msg_addrlen(NULL))); */
END();
}
......
......@@ -3697,7 +3697,6 @@ msg_select_addrinfo(msg_t *msg, su_addrinfo_t *res)
{
su_addrinfo_t *ai, *mai = msg_addrinfo(msg);
su_sockaddr_t *su = msg_addr(msg);
socklen_t *sulen = msg_addrlen(msg);
for (ai = res; ai; ai = ai->ai_next) {
#if SU_HAVE_IN6
......@@ -3717,9 +3716,9 @@ msg_select_addrinfo(msg_t *msg, su_addrinfo_t *res)
memset(su, 0, sizeof(su_sockaddr_t));
memcpy(su, ai->ai_addr, ai->ai_addrlen);
if (su_sockaddr_size(su))
*sulen = su_sockaddr_size(su);
mai->ai_addrlen = su_sockaddr_size(su);
else
*sulen = ai->ai_addrlen;
mai->ai_addrlen = ai->ai_addrlen;
return 0;
}
......
......@@ -214,8 +214,9 @@ int tport_recv_dgram(tport_t *self)
{
msg_t *msg;
int n, veclen;
su_addrinfo_t *ai;
su_sockaddr_t *from;
socklen_t *fromlen;
socklen_t fromlen;
msg_iovec_t iovec[msg_n_fragments] = {{ 0 }};
uint8_t sample[1];
......@@ -235,9 +236,13 @@ int tport_recv_dgram(tport_t *self)
msg = self->tp_msg;
n = su_vrecv(self->tp_socket, iovec, veclen, 0,
from = msg_addr(msg), fromlen = msg_addrlen(msg));
ai = msg_addrinfo(msg);
from = (su_sockaddr_t *)ai->ai_addr, fromlen = ai->ai_addrlen;
n = su_vrecv(self->tp_socket, iovec, veclen, 0, from, &fromlen);
ai->ai_addrlen = fromlen;
if (n == SOCKET_ERROR) {
int error = su_errno();
msg_destroy(msg); self->tp_msg = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment