utils.c: Remove all usages of ast_gethostbyname()

gethostbyname() and gethostbyname_r() are deprecated in favor of
getaddrinfo() which we use in the ast_sockaddr family of functions.

ASTERISK-29819 #close

Change-Id: Ie277c0ef768d753b169c121ef570a71665692ab7
This commit is contained in:
Sean Bright
2021-12-24 11:26:31 -05:00
committed by Friendly Automation
parent 8b6fca363e
commit 95fe90c746
7 changed files with 85 additions and 70 deletions

View File

@@ -281,8 +281,6 @@ static int festival_exec(struct ast_channel *chan, const char *vdata)
int usecache;
int res = 0;
struct sockaddr_in serv_addr;
struct hostent *serverhost;
struct ast_hostent ahp;
int fd;
FILE *fs;
const char *host;
@@ -398,15 +396,17 @@ static int festival_exec(struct ast_channel *chan, const char *vdata)
if ((serv_addr.sin_addr.s_addr = inet_addr(host)) == -1) {
/* its a name rather than an ipnum */
serverhost = ast_gethostbyname(host, &ahp);
struct ast_sockaddr addr = { {0,} };
if (serverhost == NULL) {
ast_log(LOG_WARNING, "festival_client: gethostbyname failed\n");
if (ast_sockaddr_resolve_first_af(&addr, host, PARSE_PORT_FORBID, AF_INET)) {
ast_log(LOG_WARNING, "festival_client: ast_sockaddr_resolve_first_af() failed\n");
ast_config_destroy(cfg);
close(fd);
return -1;
}
memmove(&serv_addr.sin_addr, serverhost->h_addr, serverhost->h_length);
/* We'll overwrite port and family in a sec */
ast_sockaddr_to_sin(&addr, &serv_addr);
}
serv_addr.sin_family = AF_INET;