[Asterisk-code-review] res hep: Adds hostname resolution support for capture address (asterisk[15])

Joshua Colp asteriskteam at digium.com
Wed May 9 19:00:23 CDT 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/8954 )

Change subject: res_hep: Adds hostname resolution support for capture_address
......................................................................

res_hep: Adds hostname resolution support for capture_address

Previously, only an IP address would be accepted for the capture_address config
setting in hep.conf.  This change allows capture_address to be a resolvable
hostname or an IP address.

ASTERISK-27796 #close
Reported-By: Sebastian Gutierrez

Change-Id: I33e1a37a8b86e20505dadeda760b861a9ef51f6f
---
M res/res_hep.c
1 file changed, 23 insertions(+), 1 deletion(-)

Approvals:
  Corey Farrell: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  Joshua Colp: Approved for Submit



diff --git a/res/res_hep.c b/res/res_hep.c
index 4e548e2..cc7028b 100644
--- a/res/res_hep.c
+++ b/res/res_hep.c
@@ -367,6 +367,27 @@
 	}
 }
 
+/*! \brief Pulls first resolved address and returns it */
+static 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;
+}
+
 /*! \brief Allocate the HEPv3 run-time data */
 static struct hepv3_runtime_data *hepv3_data_alloc(struct hepv3_global_config *config)
 {
@@ -379,10 +400,11 @@
 
 	data->sockfd = -1;
 
-	if (!ast_sockaddr_parse(&data->remote_addr, config->capture_address, PARSE_PORT_REQUIRE)) {
+	if (ast_sockaddr_resolve_first_af(&data->remote_addr, config->capture_address, PARSE_PORT_REQUIRE, AST_AF_UNSPEC)) {
 		ast_log(AST_LOG_WARNING, "Failed to create address from %s\n", config->capture_address);
 		ao2_ref(data, -1);
 		return NULL;
+
 	}
 
 	data->sockfd = socket(ast_sockaddr_is_ipv6(&data->remote_addr) ? AF_INET6 : AF_INET, SOCK_DGRAM, 0);

-- 
To view, visit https://gerrit.asterisk.org/8954
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: I33e1a37a8b86e20505dadeda760b861a9ef51f6f
Gerrit-Change-Number: 8954
Gerrit-PatchSet: 1
Gerrit-Owner: Matthew Fredrickson <creslin at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180509/01fc77d2/attachment-0001.html>


More information about the asterisk-code-review mailing list