summaryrefslogtreecommitdiff
path: root/res/res_pjsip_sdp_rtp.c
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2015-08-25 09:17:34 -0300
committerJoshua Colp <jcolp@digium.com>2015-08-25 13:55:33 -0300
commitd013ecf7486ad4a04d8ccb52340c5e62bb44b6f6 (patch)
tree2269da22459b95fc71e10faf182430ae47187478 /res/res_pjsip_sdp_rtp.c
parent6b8734fe6890dfa4754b07eceaab52a4712297a9 (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.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index f1314f528..7b705ae25 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -1033,7 +1033,7 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
static const pj_str_t STR_SENDRECV = { "sendrecv", 8 };
static const pj_str_t STR_SENDONLY = { "sendonly", 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;
@@ -1081,16 +1081,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;