<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17830">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">utils.c: Remove all usages of ast_gethostbyname()<br><br>gethostbyname() and gethostbyname_r() are deprecated in favor of<br>getaddrinfo() which we use in the ast_sockaddr family of functions.<br><br>ASTERISK-29819 #close<br><br>Change-Id: Ie277c0ef768d753b169c121ef570a71665692ab7<br>---<br>M addons/ooh323c/src/ooSocket.c<br>M apps/app_festival.c<br>M channels/chan_mgcp.c<br>M channels/chan_skinny.c<br>M channels/chan_unistim.c<br>M channels/iax2/provision.c<br>M main/config.c<br>7 files changed, 85 insertions(+), 70 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/30/17830/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/addons/ooh323c/src/ooSocket.c b/addons/ooh323c/src/ooSocket.c</span><br><span>index 151c1cf..c0457c3 100644</span><br><span>--- a/addons/ooh323c/src/ooSocket.c</span><br><span>+++ b/addons/ooh323c/src/ooSocket.c</span><br><span>@@ -537,8 +537,6 @@</span><br><span> int ooGetLocalIPAddress(char * pIPAddrs)</span><br><span> {</span><br><span> int ret;</span><br><span style="color: hsl(0, 100%, 40%);">- struct hostent *hp;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_hostent phost;</span><br><span> char hostname[100];</span><br><span> </span><br><span> if(pIPAddrs == NULL)</span><br><span>@@ -546,20 +544,11 @@</span><br><span> ret = gethostname(hostname, 100);</span><br><span> if(ret == 0)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- if ((hp = ast_gethostbyname(hostname, &phost))) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (hp->h_addrtype == AF_INET6) {</span><br><span style="color: hsl(0, 100%, 40%);">- struct in6_addr i;</span><br><span style="color: hsl(0, 100%, 40%);">- memcpy(&i, hp->h_addr, sizeof(i));</span><br><span style="color: hsl(0, 100%, 40%);">- strcpy(pIPAddrs, (inet_ntop(AF_INET6, &i,</span><br><span style="color: hsl(0, 100%, 40%);">- hostname, sizeof(hostname))) == NULL ? "::1" :</span><br><span style="color: hsl(0, 100%, 40%);">- inet_ntop(AF_INET6, &i, hostname, sizeof(hostname)));</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- struct in_addr i;</span><br><span style="color: hsl(0, 100%, 40%);">- memcpy(&i, hp->h_addr, sizeof(i));</span><br><span style="color: hsl(0, 100%, 40%);">- strcpy(pIPAddrs, (ast_inet_ntoa(i) == NULL) ? "127.0.0.1" : ast_inet_ntoa(i));</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sockaddr addr = { {0,} };</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sockaddr_resolve_first_af(&addr, hostname, PARSE_PORT_FORBID, AF_UNSPEC)) {</span><br><span> return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ strcpy(pIPAddrs, ast_sockaddr_stringify_addr(&addr));</span><br><span> }</span><br><span> }</span><br><span> else{</span><br><span>diff --git a/apps/app_festival.c b/apps/app_festival.c</span><br><span>index d682b1c..c18725d 100644</span><br><span>--- a/apps/app_festival.c</span><br><span>+++ b/apps/app_festival.c</span><br><span>@@ -281,8 +281,6 @@</span><br><span> int usecache;</span><br><span> int res = 0;</span><br><span> struct sockaddr_in serv_addr;</span><br><span style="color: hsl(0, 100%, 40%);">- struct hostent *serverhost;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_hostent ahp;</span><br><span> int fd;</span><br><span> FILE *fs;</span><br><span> const char *host;</span><br><span>@@ -398,15 +396,17 @@</span><br><span> </span><br><span> if ((serv_addr.sin_addr.s_addr = inet_addr(host)) == -1) {</span><br><span> /* its a name rather than an ipnum */</span><br><span style="color: hsl(0, 100%, 40%);">- serverhost = ast_gethostbyname(host, &ahp);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sockaddr addr = { {0,} };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (serverhost == NULL) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "festival_client: gethostbyname failed\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sockaddr_resolve_first_af(&addr, host, PARSE_PORT_FORBID, AF_INET)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "festival_client: ast_sockaddr_resolve_first_af() failed\n");</span><br><span> ast_config_destroy(cfg);</span><br><span> close(fd);</span><br><span> return -1;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- memmove(&serv_addr.sin_addr, serverhost->h_addr, serverhost->h_length);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* We'll overwrite port and family in a sec */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sockaddr_to_sin(&addr, &serv_addr);</span><br><span> }</span><br><span> </span><br><span> serv_addr.sin_family = AF_INET;</span><br><span>diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c</span><br><span>index 3a0c7b3..b2f1e57 100644</span><br><span>--- a/channels/chan_mgcp.c</span><br><span>+++ b/channels/chan_mgcp.c</span><br><span>@@ -1949,10 +1949,8 @@</span><br><span> int portno;</span><br><span> struct ast_format_cap *peercap;</span><br><span> int peerNonCodecCapability;</span><br><span style="color: hsl(0, 100%, 40%);">- struct sockaddr_in sin;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_sockaddr sin_tmp;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sockaddr addr = { {0,} };</span><br><span> char *codecs;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_hostent ahp; struct hostent *hp;</span><br><span> int codec, codec_count=0;</span><br><span> int iterator;</span><br><span> struct mgcp_endpoint *p = sub->parent;</span><br><span>@@ -1972,8 +1970,7 @@</span><br><span> return -1;</span><br><span> }</span><br><span> /* XXX This could block for a long time, and block the main thread! XXX */</span><br><span style="color: hsl(0, 100%, 40%);">- hp = ast_gethostbyname(host, &ahp);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!hp) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sockaddr_resolve_first_af(&addr, host, PARSE_PORT_FORBID, AF_INET)) {</span><br><span> ast_log(LOG_WARNING, "Unable to lookup host in c= line, '%s'\n", c);</span><br><span> return -1;</span><br><span> }</span><br><span>@@ -1981,12 +1978,9 @@</span><br><span> ast_log(LOG_WARNING, "Malformed media stream descriptor: %s\n", m);</span><br><span> return -1;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- sin.sin_family = AF_INET;</span><br><span style="color: hsl(0, 100%, 40%);">- memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));</span><br><span style="color: hsl(0, 100%, 40%);">- sin.sin_port = htons(portno);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sockaddr_from_sin(&sin_tmp, &sin);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_rtp_instance_set_remote_address(sub->rtp, &sin_tmp);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(3, "Peer RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sockaddr_set_port(&addr, portno);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_rtp_instance_set_remote_address(sub->rtp, &addr);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(3, "Peer RTP is at port %s\n", ast_sockaddr_stringify(&addr));</span><br><span> /* Scan through the RTP payload types specified in a "m=" line: */</span><br><span> codecs = ast_strdupa(m + len);</span><br><span> while (!ast_strlen_zero(codecs)) {</span><br><span>@@ -4651,6 +4645,30 @@</span><br><span> return res;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Resolve the given hostname and save its IPv4 address.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] hostname The hostname to resolve.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] sin_addr Pointer to a <tt>struct in_addr</tt> in which to</span><br><span style="color: hsl(120, 100%, 40%);">+ * store the resolved IPv4 address. \c sin_addr will</span><br><span style="color: hsl(120, 100%, 40%);">+ * not be changed if resolution fails.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 if successful</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 1 on failure</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int resolve_first_addr(const char *hostname, struct in_addr *sin_addr)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sockaddr addr = { {0,} };</span><br><span style="color: hsl(120, 100%, 40%);">+ struct sockaddr_in tmp;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sockaddr_resolve_first_af(&addr, hostname, PARSE_PORT_FORBID, AF_INET)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sockaddr_to_sin(&addr, &tmp);</span><br><span style="color: hsl(120, 100%, 40%);">+ *sin_addr = tmp.sin_addr;</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span> </span><br><span> static int reload_config(int reload)</span><br><span> {</span><br><span>@@ -4659,8 +4677,6 @@</span><br><span> struct mgcp_gateway *g;</span><br><span> struct mgcp_endpoint *e;</span><br><span> char *cat;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_hostent ahp;</span><br><span style="color: hsl(0, 100%, 40%);">- struct hostent *hp;</span><br><span> struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };</span><br><span> </span><br><span> if (gethostname(ourhost, sizeof(ourhost)-1)) {</span><br><span>@@ -4694,10 +4710,8 @@</span><br><span> </span><br><span> /* Create the interface list */</span><br><span> if (!strcasecmp(v->name, "bindaddr")) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(hp = ast_gethostbyname(v->value, &ahp))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (resolve_first_addr(v->value, &bindaddr.sin_addr)) {</span><br><span> ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));</span><br><span> }</span><br><span> } else if (!strcasecmp(v->name, "allow")) {</span><br><span> ast_format_cap_update_by_allow_disallow(global_capability, v->value, 1);</span><br><span>@@ -4765,13 +4779,11 @@</span><br><span> if (ntohl(bindaddr.sin_addr.s_addr)) {</span><br><span> memcpy(&__ourip, &bindaddr.sin_addr, sizeof(__ourip));</span><br><span> } else {</span><br><span style="color: hsl(0, 100%, 40%);">- hp = ast_gethostbyname(ourhost, &ahp);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!hp) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (resolve_first_addr(ourhost, &__ourip)) {</span><br><span> ast_log(LOG_WARNING, "Unable to get our IP address, MGCP disabled\n");</span><br><span> ast_config_destroy(cfg);</span><br><span> return 0;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- memcpy(&__ourip, hp->h_addr, sizeof(__ourip));</span><br><span> }</span><br><span> if (!ntohs(bindaddr.sin_port))</span><br><span> bindaddr.sin_port = htons(DEFAULT_MGCP_CA_PORT);</span><br><span>diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c</span><br><span>index 788d3ec..e3a7021 100644</span><br><span>--- a/channels/chan_skinny.c</span><br><span>+++ b/channels/chan_skinny.c</span><br><span>@@ -1235,8 +1235,6 @@</span><br><span> static char ourhost[256];</span><br><span> static int ourport;</span><br><span> static struct in_addr __ourip;</span><br><span style="color: hsl(0, 100%, 40%);">-static struct ast_hostent ahp;</span><br><span style="color: hsl(0, 100%, 40%);">-static struct hostent *hp;</span><br><span> static int skinnysock = -1;</span><br><span> static pthread_t accept_t;</span><br><span> static int callnums = 1;</span><br><span>@@ -7759,6 +7757,31 @@</span><br><span> return tmpc;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Resolve the given hostname and save its IPv4 address.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[in] hostname The hostname to resolve.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param[out] sin_addr Pointer to a <tt>struct in_addr</tt> in which to</span><br><span style="color: hsl(120, 100%, 40%);">+ * store the resolved IPv4 address. \c sin_addr will</span><br><span style="color: hsl(120, 100%, 40%);">+ * not be changed if resolution fails.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 if successful</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 1 on failure</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int resolve_first_addr(const char *hostname, struct in_addr *sin_addr)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sockaddr addr = { {0,} };</span><br><span style="color: hsl(120, 100%, 40%);">+ struct sockaddr_in tmp;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sockaddr_resolve_first_af(&addr, hostname, PARSE_PORT_FORBID, AF_INET)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sockaddr_to_sin(&addr, &tmp);</span><br><span style="color: hsl(120, 100%, 40%);">+ *sin_addr = tmp.sin_addr;</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #define TYPE_GENERAL 1</span><br><span> #define TYPE_DEF_DEVICE 2</span><br><span> #define TYPE_DEF_LINE 4</span><br><span>@@ -7790,10 +7813,8 @@</span><br><span> continue;</span><br><span> }</span><br><span> if (!strcasecmp(v->name, "bindaddr")) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(hp = ast_gethostbyname(v->value, &ahp))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (resolve_first_addr(v->value, &bindaddr.sin_addr)) {</span><br><span> ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));</span><br><span> }</span><br><span> continue;</span><br><span> } else if (!strcasecmp(v->name, "keepalive")) {</span><br><span>@@ -8480,13 +8501,11 @@</span><br><span> if (ntohl(bindaddr.sin_addr.s_addr)) {</span><br><span> __ourip = bindaddr.sin_addr;</span><br><span> } else {</span><br><span style="color: hsl(0, 100%, 40%);">- hp = ast_gethostbyname(ourhost, &ahp);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!hp) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (resolve_first_addr(ourhost, &__ourip)) {</span><br><span> ast_log(LOG_WARNING, "Unable to get our IP address, Skinny disabled\n");</span><br><span> ast_config_destroy(cfg);</span><br><span> return 0;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- memcpy(&__ourip, hp->h_addr, sizeof(__ourip));</span><br><span> }</span><br><span> if (!ntohs(bindaddr.sin_port)) {</span><br><span> bindaddr.sin_port = htons(DEFAULT_SKINNY_PORT);</span><br><span>diff --git a/channels/chan_unistim.c b/channels/chan_unistim.c</span><br><span>index 0240509..f813e34 100644</span><br><span>--- a/channels/chan_unistim.c</span><br><span>+++ b/channels/chan_unistim.c</span><br><span>@@ -6847,8 +6847,6 @@</span><br><span> {</span><br><span> struct ast_config *cfg;</span><br><span> struct ast_variable *v;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_hostent ahp;</span><br><span style="color: hsl(0, 100%, 40%);">- struct hostent *hp;</span><br><span> struct sockaddr_in bindaddr = { 0, };</span><br><span> char *config = "unistim.conf";</span><br><span> char *cat;</span><br><span>@@ -6916,11 +6914,11 @@</span><br><span> }</span><br><span> } else if (!strcasecmp(v->name, "public_ip")) {</span><br><span> if (!ast_strlen_zero(v->value)) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(hp = ast_gethostbyname(v->value, &ahp))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sockaddr addr = { {0,} };</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sockaddr_resolve_first_af(&addr, v->value, PARSE_PORT_FORBID, AF_INET)) {</span><br><span> ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);</span><br><span> } else {</span><br><span style="color: hsl(0, 100%, 40%);">- memcpy(&public_ip.sin_addr, hp->h_addr, sizeof(public_ip.sin_addr));</span><br><span style="color: hsl(0, 100%, 40%);">- public_ip.sin_family = AF_INET;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sockaddr_to_sin(&addr, &public_ip);</span><br><span> }</span><br><span> }</span><br><span> }</span><br><span>diff --git a/channels/iax2/provision.c b/channels/iax2/provision.c</span><br><span>index f21c4e6..d67a73f 100644</span><br><span>--- a/channels/iax2/provision.c</span><br><span>+++ b/channels/iax2/provision.c</span><br><span>@@ -285,9 +285,6 @@</span><br><span> int foundportno = 0;</span><br><span> int foundserverportno = 0;</span><br><span> int x;</span><br><span style="color: hsl(0, 100%, 40%);">- struct in_addr ia;</span><br><span style="color: hsl(0, 100%, 40%);">- struct hostent *hp;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_hostent h;</span><br><span> struct iax_template *src, tmp;</span><br><span> const char *t;</span><br><span> if (def) {</span><br><span>@@ -335,15 +332,15 @@</span><br><span> } else</span><br><span> ast_log(LOG_WARNING, "Ignoring invalid %s '%s' for '%s' at line %d\n", v->name, v->value, s, v->lineno);</span><br><span> } else if (!strcasecmp(v->name, "server") || !strcasecmp(v->name, "altserver")) {</span><br><span style="color: hsl(0, 100%, 40%);">- hp = ast_gethostbyname(v->value, &h);</span><br><span style="color: hsl(0, 100%, 40%);">- if (hp) {</span><br><span style="color: hsl(0, 100%, 40%);">- memcpy(&ia, hp->h_addr, sizeof(ia));</span><br><span style="color: hsl(0, 100%, 40%);">- if (!strcasecmp(v->name, "server"))</span><br><span style="color: hsl(0, 100%, 40%);">- cur->server = ntohl(ia.s_addr);</span><br><span style="color: hsl(0, 100%, 40%);">- else</span><br><span style="color: hsl(0, 100%, 40%);">- cur->altserver = ntohl(ia.s_addr);</span><br><span style="color: hsl(0, 100%, 40%);">- } else</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sockaddr addr = { {0,} };</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sockaddr_resolve_first_af(&addr, v->value, PARSE_PORT_FORBID, AF_INET)) {</span><br><span> ast_log(LOG_WARNING, "Ignoring invalid %s '%s' for '%s' at line %d\n", v->name, v->value, s, v->lineno);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strcasecmp(v->name, "server"))</span><br><span style="color: hsl(120, 100%, 40%);">+ cur->server = ast_sockaddr_ipv4(&addr);</span><br><span style="color: hsl(120, 100%, 40%);">+ else</span><br><span style="color: hsl(120, 100%, 40%);">+ cur->altserver = ast_sockaddr_ipv4(&addr);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } else if (!strcasecmp(v->name, "codec")) {</span><br><span> struct ast_format *tmpfmt;</span><br><span> if ((tmpfmt = ast_format_cache_get(v->value))) {</span><br><span>diff --git a/main/config.c b/main/config.c</span><br><span>index 4d4f946..7b3b457 100644</span><br><span>--- a/main/config.c</span><br><span>+++ b/main/config.c</span><br><span>@@ -3863,8 +3863,7 @@</span><br><span> /* default is either the supplied value or the result itself */</span><br><span> struct sockaddr_in *def = (flags & PARSE_DEFAULT) ?</span><br><span> va_arg(ap, struct sockaddr_in *) : sa;</span><br><span style="color: hsl(0, 100%, 40%);">- struct hostent *hp;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_hostent ahp;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sockaddr addr = { {0,} };</span><br><span> </span><br><span> memset(&_sa_buf, '\0', sizeof(_sa_buf)); /* clear buffer */</span><br><span> /* duplicate the string to strip away the :port */</span><br><span>@@ -3890,12 +3889,13 @@</span><br><span> error = 1;</span><br><span> }</span><br><span> /* Now deal with host part, even if we have errors before. */</span><br><span style="color: hsl(0, 100%, 40%);">- hp = ast_gethostbyname(buf, &ahp);</span><br><span style="color: hsl(0, 100%, 40%);">- if (hp) /* resolved successfully */</span><br><span style="color: hsl(0, 100%, 40%);">- memcpy(&sa->sin_addr, hp->h_addr, sizeof(sa->sin_addr));</span><br><span style="color: hsl(0, 100%, 40%);">- else {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sockaddr_resolve_first_af(&addr, buf, PARSE_PORT_FORBID, AF_INET)) {</span><br><span> error = 1;</span><br><span> sa->sin_addr = def->sin_addr;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct sockaddr_in tmp;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sockaddr_to_sin(&addr, &tmp);</span><br><span style="color: hsl(120, 100%, 40%);">+ sa->sin_addr = tmp.sin_addr;</span><br><span> }</span><br><span> ast_debug(3,</span><br><span> "extract inaddr from [%s] gives [%s:%d](%d)\n",</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17830">change 17830</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/17830"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 19 </div>
<div style="display:none"> Gerrit-Change-Id: Ie277c0ef768d753b169c121ef570a71665692ab7 </div>
<div style="display:none"> Gerrit-Change-Number: 17830 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>