Commit b790f62e authored by Pekka Pessi's avatar Pekka Pessi

su_addrinfo.c: fixed Solaris addrinfo() which returns 0 in ai_protocol

This caused an assertion failure in tport.c on Solaris.

darcs-hash:20070222203347-88462-92bb0549818eb67da9b3de4cb192c78e898e16a4.gz
parent 7a7e4e16
......@@ -887,10 +887,13 @@ int su_getaddrinfo(char const *node, char const *service,
su_addrinfo_t const *hints,
su_addrinfo_t **res)
{
int retval;
su_addrinfo_t *ai;
#if HAVE_SCTP
if (res && hints && hints->ai_protocol == IPPROTO_SCTP) {
su_addrinfo_t *ai, system_hints[1];
int retval, socktype;
su_addrinfo_t system_hints[1];
int socktype;
socktype = hints->ai_socktype;
......@@ -920,7 +923,31 @@ int su_getaddrinfo(char const *node, char const *service,
}
#endif
return getaddrinfo(node, service, hints, res);
retval = getaddrinfo(node, service, hints, res);
if (retval == 0) {
for (ai = *res; ai; ai = ai->ai_next) {
if (ai->ai_protocol)
continue;
if (hints && hints->ai_protocol) {
ai->ai_protocol = hints->ai_protocol;
continue;
}
if (ai->ai_family != AF_INET
#if SU_HAVE_IN6
&& ai->ai_family != AF_INET6
#endif
) continue;
if (ai->ai_socktype == SOCK_STREAM)
ai->ai_protocol = IPPROTO_TCP;
else if (ai->ai_socktype == SOCK_DGRAM)
ai->ai_protocol = IPPROTO_UDP;
}
}
return retval;
}
/** Free su_addrinfo_t structure allocated by su_getaddrinfo(). */
......
......@@ -3271,6 +3271,7 @@ int tport_send_msg(tport_t *self, msg_t *msg,
/* We have sent a complete message */
self->tp_slogged = NULL;
self->tp_stats.sent_msgs ++;
ai = msg_addrinfo(msg); assert(ai);
close_after = (ai->ai_flags & TP_AI_CLOSE) == TP_AI_CLOSE;
......@@ -3690,8 +3691,11 @@ void tport_send_queue(tport_t *self)
}
assert(total == n);
/* We have sent a complete message */
self->tp_queue[qhead] = NULL;
msg_destroy(msg);
self->tp_stats.sent_msgs++;
self->tp_slogged = NULL;
qhead = (qhead + 1) % N;
......@@ -3792,11 +3796,15 @@ msg_select_addrinfo(msg_t *msg, su_addrinfo_t *res)
continue;
#endif
if (ai->ai_protocol == 0)
continue;
if (ai->ai_addrlen > sizeof(su_sockaddr_t))
continue;
mai->ai_family = ai->ai_family;
mai->ai_socktype = ai->ai_socktype;
mai->ai_protocol = ai->ai_protocol;
if (ai->ai_addrlen < sizeof(su_sockaddr_t))
memset(su, 0, sizeof(su_sockaddr_t));
memcpy(su, ai->ai_addr, ai->ai_addrlen);
......
......@@ -180,9 +180,6 @@ static int tport_sctp_init_secondary(tport_t *self, int socket, int accepted,
{
self->tp_has_connection = 1;
if (su_setblocking(socket, 0) < 0)
return *return_reason = "su_setblocking", -1;
if (accepted) {
/* Accepted socket inherit the init information from listen socket */
return 0;
......
......@@ -175,8 +175,6 @@ int tport_tcp_init_secondary(tport_t *self, int socket, int accepted,
if (setsockopt(socket, SOL_TCP, TCP_NODELAY, (void *)&one, sizeof one) == -1)
return *return_reason = "TCP_NODELAY", -1;
if (su_setblocking(socket, 0) < 0)
return *return_reason = "su_setblocking", -1;
if (!accepted)
tport_tcp_setsndbuf(socket, 64 * 1024);
......
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