netsock2: Add ast_sockaddr_resolve_first_af to netsock2 public API

This function originally was used in chan_sip to enable some simplifying
assumptions and eventually was copy and pasted into res_pjsip_logger and
res_hep.  Since it's replicated in three places, it's probably best to
move it into the public netsock2 API for these modules to use.

Change-Id: Id52e23be885601c51d70259f62de1a5e59d38d04
This commit is contained in:
Matthew Fredrickson
2018-05-14 06:07:34 -05:00
parent a103221de2
commit 9f9dce05b2
5 changed files with 59 additions and 72 deletions

View File

@@ -333,6 +333,27 @@ cleanup:
return res_cnt;
}
/*! \brief Pulls first resolved address and returns it */
int ast_sockaddr_resolve_first_af(struct ast_sockaddr *addr,
const char* name, int flag, int family)
{
struct ast_sockaddr *addrs;
int addrs_cnt;
addrs_cnt = ast_sockaddr_resolve(&addrs, name, flag, family);
if (addrs_cnt <= 0) {
return 1;
}
if (addrs_cnt > 1) {
ast_debug(1, "Multiple addresses resolving %s, using the first one only\n", name);
}
ast_sockaddr_copy(addr, &addrs[0]);
ast_free(addrs);
return 0;
}
int ast_sockaddr_apply_netmask(const struct ast_sockaddr *addr, const struct ast_sockaddr *netmask,
struct ast_sockaddr *result)
{