#define STUN_UNKNOWN_ATTRIBUTES 0x000a
#define STUN_REFLECTED_FROM 0x000b
+#define STUN_MAX_RETRIES 3
+
/*! \brief helper function to print message names */
static const char *stun_msg2str(int msg)
{
}
}
+static void handle_stun_timeout(int retry, struct sockaddr_in *dst)
+{
+ if (retry < STUN_MAX_RETRIES) {
+ ast_log(LOG_NOTICE,
+ "Attempt %d to send STUN request to '%s' timed out.",
+ retry,
+ ast_inet_ntoa(dst->sin_addr));
+ } else {
+ ast_log(LOG_WARNING,
+ "Attempt %d to send STUN request to '%s' timed out."
+ "Check that the server address is correct and reachable.\n",
+ retry,
+ ast_inet_ntoa(dst->sin_addr));
+ }
+}
+
/*! \brief wrapper to send an STUN message */
static int stun_send(int s, struct sockaddr_in *dst, struct stun_header *resp)
{
req->msglen = htons(reqlen);
req->msgtype = htons(STUN_BINDREQ);
- for (retry = 0; retry++ < 3;) { /* XXX make retries configurable */
+ for (retry = 0; retry++ < STUN_MAX_RETRIES;) { /* XXX make retries configurable */
/* send request, possibly wait for reply */
struct sockaddr_in src;
socklen_t srclen;
ms = ast_remaining_ms(start, 3000);
if (ms <= 0) {
/* No response, timeout */
+ handle_stun_timeout(retry, dst);
res = 1;
continue;
}
}
if (!res) {
/* No response, timeout */
+ handle_stun_timeout(retry, dst);
res = 1;
continue;
}