Commit 4af758de authored by Pekka Pessi's avatar Pekka Pessi
Browse files

Added compilation and run-time checks for MSG_TRUNC.

darcs-hash:20060425092811-65a35-a63787c7c8e096e115d027a7041555cea9271dc9.gz
parent 6820943a
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#ifndef SU_H #ifndef SU_H
#include <sofia-sip/su.h> #include <sofia-sip/su.h>
#endif #endif
#include <sofia-sip/su_uniqueid.h> #include <sofia-sip/su_uniqueid.h>
#ifndef MSG_ADDR_H #ifndef MSG_ADDR_H
...@@ -64,8 +65,7 @@ ...@@ -64,8 +65,7 @@
#define MSG_NOSIGNAL (0) #define MSG_NOSIGNAL (0)
#endif #endif
#if !defined(MSG_TRUNC) || defined(SU_HAVE_WINSOCK) #if !HAVE_MSG_TRUNC
#undef MSG_TRUNC
#define MSG_TRUNC (0) #define MSG_TRUNC (0)
#endif #endif
...@@ -136,6 +136,7 @@ struct tport_s { ...@@ -136,6 +136,7 @@ struct tport_s {
unsigned tp_send_close:2; unsigned tp_send_close:2;
unsigned tp_has_keepalive:1; unsigned tp_has_keepalive:1;
unsigned tp_has_stun_server:1; unsigned tp_has_stun_server:1;
unsigned tp_trunc:1;
unsigned:0; unsigned:0;
tport_t *tp_left, *tp_right, *tp_dad; /**< Links in tport tree */ tport_t *tp_left, *tp_right, *tp_dad; /**< Links in tport tree */
......
...@@ -441,7 +441,7 @@ int thrp_udp_recv(tport_threadpool_t *thrp, thrp_udp_deliver_t *tpd) ...@@ -441,7 +441,7 @@ int thrp_udp_recv(tport_threadpool_t *thrp, thrp_udp_deliver_t *tpd)
recv(s, sample, sizeof sample, 0); recv(s, sample, sizeof sample, 0);
N = 0; N = 0;
} }
#if !MSG_TRUNC #if !HAVE_MSG_TRUNC
else if ((N = su_getmsgsize(tp->tp_socket)) < 0) else if ((N = su_getmsgsize(tp->tp_socket)) < 0)
; ;
#endif #endif
......
...@@ -87,6 +87,8 @@ tport_vtable_t const tport_udp_vtable = ...@@ -87,6 +87,8 @@ tport_vtable_t const tport_udp_vtable =
tport_send_dgram, tport_send_dgram,
}; };
static void tport_check_trunc(tport_t *tp, su_addrinfo_t *ai);
int tport_udp_init_primary(tport_primary_t *pri, int tport_udp_init_primary(tport_primary_t *pri,
tp_name_t tpn[1], tp_name_t tpn[1],
su_addrinfo_t *ai, su_addrinfo_t *ai,
...@@ -144,11 +146,42 @@ int tport_udp_init_primary(tport_primary_t *pri, ...@@ -144,11 +146,42 @@ int tport_udp_init_primary(tport_primary_t *pri,
pri->pri_primary->tp_events = events; pri->pri_primary->tp_events = events;
tport_check_trunc(pri->pri_primary, ai);
tport_stun_server_add_socket(pri->pri_primary); tport_stun_server_add_socket(pri->pri_primary);
return 0; return 0;
} }
/** Runtime test making sure MSG_TRUNC work as expected */
static void tport_check_trunc(tport_t *tp, su_addrinfo_t *ai)
{
#if HAVE_MSG_TRUNC
int n;
char buffer[2];
su_sockaddr_t su[1];
socklen_t sulen = sizeof su;
n = sendto(tp->tp_socket,
"TEST", 4, 0,
(void *)ai->ai_addr, ai->ai_addrlen);
for (;;) {
n = recvfrom(tp->tp_socket, buffer, sizeof buffer, MSG_TRUNC,
(void *)&su, &sulen);
if (n > sizeof buffer) {
tp->tp_trunc = 1;
return;
}
/* XXX - check that su and tp->tp_addrinfo->ai_addr match */
return;
}
#endif
}
/** Receive datagram. /** Receive datagram.
* *
* @retval -1 error * @retval -1 error
...@@ -182,11 +215,9 @@ int tport_recv_dgram(tport_t *self) ...@@ -182,11 +215,9 @@ int tport_recv_dgram(tport_t *self)
recv(s, sample, sizeof sample, 0); recv(s, sample, sizeof sample, 0);
N = 0; N = 0;
} }
#if MSG_TRUNC else if (self->tp_trunc ? 0 : (N = su_getmsgsize(s)) < 0)
else if ((N = su_getmsgsize(s)) < 0)
SU_DEBUG_1(("%s: su_getmsgsize(): %s (%d)\n", __func__, SU_DEBUG_1(("%s: su_getmsgsize(): %s (%d)\n", __func__,
su_strerror(su_errno()), su_errno())); su_strerror(su_errno()), su_errno()));
#endif
else if ((sample[0] & 0xf8) == 0xf8) { else if ((sample[0] & 0xf8) == 0xf8) {
return tport_recv_comp_dgram(self, N); /* SigComp */ return tport_recv_comp_dgram(self, N); /* SigComp */
} }
...@@ -396,4 +427,3 @@ int tport_udp_error(tport_t const *self, su_sockaddr_t name[1]) ...@@ -396,4 +427,3 @@ int tport_udp_error(tport_t const *self, su_sockaddr_t name[1])
return 0; return 0;
} }
#endif #endif
...@@ -146,6 +146,11 @@ AC_CHECK_HEADERS([netinet/in.h arpa/inet.h netdb.h \ ...@@ -146,6 +146,11 @@ AC_CHECK_HEADERS([netinet/in.h arpa/inet.h netdb.h \
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h>]) #include <sys/socket.h>])
AC_CHECK_DECL([MSG_TRUNC],
AC_DEFINE([HAVE_MSG_TRUNC],1,[Define to 1 if you have MSG_TRUNC flag]),,[
#include <sys/types.h>
#include <sys/socket.h>])
AC_CACHE_CHECK([for struct addrinfo], AC_CACHE_CHECK([for struct addrinfo],
[ac_cv_struct_addrinfo],[ [ac_cv_struct_addrinfo],[
ac_cv_struct_addrinfo=no ac_cv_struct_addrinfo=no
......
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