diff options
author | Joshua Colp <jcolp@digium.com> | 2015-08-25 09:17:34 -0300 |
---|---|---|
committer | Joshua Colp <jcolp@digium.com> | 2015-08-25 13:54:26 -0300 |
commit | 2a4eee0cd9df5db7fd0e7bcf20c72f920003bd07 (patch) | |
tree | d8c50aba656e9baee92cd859f25d22496d8702fa /res/res_pjsip_sdp_rtp.c | |
parent | d238cf33a9bfe86f9ebdb204384df820098c2670 (diff) |
res_pjsip: Add common ast_sip_get_host_ip API.
Modules commonly used the pj_gethostip function for retrieving the
IP address of the host. This function does not cache the result and may
result in a DNS lookup occurring, or additional work. If the DNS
server is unreachable or network issues arise this can cause the
pj_gethostip function to block for a period of time.
This change adds an ast_sip_get_host_ip and ast_sip_get_host_ip_string
function which does the same thing but caches the host IP address at
module load time. This results in no additional work being done each
time the local host IP address is needed.
ASTERISK-25342 #close
Change-Id: I3205deb679b01fa5ac05a94b623bfd620a2abe1e
Diffstat (limited to 'res/res_pjsip_sdp_rtp.c')
-rw-r--r-- | res/res_pjsip_sdp_rtp.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c index 0a5cbcbf9..5faf4d3f5 100644 --- a/res/res_pjsip_sdp_rtp.c +++ b/res/res_pjsip_sdp_rtp.c @@ -1023,7 +1023,7 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as static const pj_str_t STR_IP6 = { "IP6", 3}; static const pj_str_t STR_SENDRECV = { "sendrecv", 8 }; pjmedia_sdp_media *media; - char hostip[PJ_INET6_ADDRSTRLEN+2]; + const char *hostip = NULL; struct ast_sockaddr addr; char tmp[512]; pj_str_t stmp; @@ -1071,16 +1071,16 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as /* Add connection level details */ if (direct_media_enabled) { - ast_copy_string(hostip, ast_sockaddr_stringify_fmt(&session_media->direct_media_addr, AST_SOCKADDR_STR_ADDR), sizeof(hostip)); + hostip = ast_sockaddr_stringify_fmt(&session_media->direct_media_addr, AST_SOCKADDR_STR_ADDR); } else if (ast_strlen_zero(session->endpoint->media.address)) { - pj_sockaddr localaddr; - - if (pj_gethostip(session->endpoint->media.rtp.ipv6 ? pj_AF_INET6() : pj_AF_INET(), &localaddr)) { - return -1; - } - pj_sockaddr_print(&localaddr, hostip, sizeof(hostip), 2); + hostip = ast_sip_get_host_ip_string(session->endpoint->media.rtp.ipv6 ? pj_AF_INET6() : pj_AF_INET()); } else { - ast_copy_string(hostip, session->endpoint->media.address, sizeof(hostip)); + hostip = session->endpoint->media.address; + } + + if (ast_strlen_zero(hostip)) { + ast_log(LOG_ERROR, "No local host IP available for stream %s\n", session_media->stream_type); + return -1; } media->conn->net_type = STR_IN; |