--- asterisk-1.8.6.0.orig/res/res_rtp_asterisk.c 2011-07-19 19:57:18.000000000 +0200 +++ asterisk-1.8.6.0/res/res_rtp_asterisk.c 2011-09-08 14:46:22.000000000 +0200 @@ -2072,11 +2072,29 @@ if (!(version = (seqno & 0xC0000000) >> 30)) { struct sockaddr_in addr_tmp; - ast_sockaddr_to_sin(&addr, &addr_tmp); - if ((ast_stun_handle_packet(rtp->s, &addr_tmp, rtp->rawdata + AST_FRIENDLY_OFFSET, res, NULL, NULL) == AST_STUN_ACCEPT) && - ast_sockaddr_isnull(&remote_address)) { - ast_sockaddr_from_sin(&addr, &addr_tmp); - ast_rtp_instance_set_remote_address(instance, &addr); + struct ast_sockaddr addr_v4; + int got_v4; + if (ast_sockaddr_is_ipv4(&addr)) { + ast_sockaddr_to_sin(&addr, &addr_tmp); + got_v4 = 1; + } + else if (ast_sockaddr_ipv4_mapped(&addr, &addr_v4)) { + ast_debug(1, "Using IPv6 mapped address %s\n", + ast_sockaddr_stringify(&addr)); + ast_sockaddr_to_sin(&addr_v4, &addr_tmp); + got_v4 = 1; + } + else { + ast_debug(1, "Cannot do STUN for address %s\n", + ast_sockaddr_stringify(&addr)); + got_v4 = 0; + } + if (got_v4) { + if ((ast_stun_handle_packet(rtp->s, &addr_tmp, rtp->rawdata + AST_FRIENDLY_OFFSET, res, NULL, NULL) == AST_STUN_ACCEPT) && + ast_sockaddr_isnull(&remote_address)) { + ast_sockaddr_from_sin(&addr, &addr_tmp); + ast_rtp_instance_set_remote_address(instance, &addr); + } } return &ast_null_frame; }