mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
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
This commit is contained in:
@@ -707,7 +707,7 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
|
||||
static const pj_str_t STR_T38UDPREDUNDANCY = { "t38UDPRedundancy", 16 };
|
||||
struct t38_state *state;
|
||||
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;
|
||||
@@ -732,14 +732,13 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
|
||||
media->desc.transport = STR_UDPTL;
|
||||
|
||||
if (ast_strlen_zero(session->endpoint->media.address)) {
|
||||
pj_sockaddr localaddr;
|
||||
|
||||
if (pj_gethostip(session->endpoint->media.t38.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.t38.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)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
media->conn->net_type = STR_IN;
|
||||
|
Reference in New Issue
Block a user