From b42bf2a3cd52b5f2ed03f9515c0510f802cc4e65 Mon Sep 17 00:00:00 2001
From: Iryna Antsyferova <iryna.antsyferova@genexis.eu>
Date: Tue, 19 Nov 2024 16:15:28 +0100
Subject: [PATCH] Add FQDN name to "pjsip show srv_lookups" CLI command, REF
 15305

---
 res/res_pjsip/pjsip_resolver.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/res/res_pjsip/pjsip_resolver.c b/res/res_pjsip/pjsip_resolver.c
index acf903c558..491b457a95 100644
--- a/res/res_pjsip/pjsip_resolver.c
+++ b/res/res_pjsip/pjsip_resolver.c
@@ -1507,7 +1507,9 @@ static char *cli_show_tasks(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
 {
 	char addr[PJ_INET6_ADDRSTRLEN + 10];
 	struct host_cache_entry *host = NULL;
-	int idx;
+	struct dns_cache_record *current;
+	struct dns_cache_record *next;
+	int idx, cnt;
 	char tbuf[64];
 
 	switch (cmd) {
@@ -1525,11 +1527,13 @@ static char *cli_show_tasks(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
 
 	ast_cli(a->fd,
 		"<Host name.............................> "
+		"<Target name......................................> "
 		"<IP address.............> <Port> <Transport.....> "
 		"<Priority> <Weight> <Expired at>\n"
 		"============================================================="
 		"============================================================="
-		"======\n");
+		"============================================================="
+		"=====\n");
 
 	AST_LIST_LOCK(&dns_host_cache);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&dns_host_cache, host, list) {
@@ -1537,15 +1541,17 @@ static char *cli_show_tasks(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
 			ast_cli(a->fd, "%-40.40s   Resolving...\n", host->target.addr.host.ptr);
 			continue;
 		}
-		for (idx = 0; idx < host->addresses.count; ++idx) {
-			ast_cli(a->fd, "%-40.40s %-25.25s %-6d %-15.15s %10d %8d %-24s\n",
+		for (cnt = 0, current = host->a_records.first, next = current ? current->list.next : NULL; current;
+			cnt++, current = next, next = current ? current->list.next : NULL) {
+			ast_cli(a->fd, "%-40.40s %-40.40s %-25.25s %-6d %-15.15s %10d %8d %-24s\n",
 				host->target.addr.host.ptr,
-				pj_sockaddr_print(&host->addresses.entry[idx].addr, addr, sizeof(addr), 2),
-				pj_sockaddr_get_port(&host->addresses.entry[idx].addr),
+				current->name,
+				pj_sockaddr_print(&host->addresses.entry[cnt].addr, addr, sizeof(addr), 2),
+				pj_sockaddr_get_port(&host->addresses.entry[cnt].addr),
 				pjsip_transport_get_type_desc(host->target.type),
-				host->addresses.entry[idx].priority,
-				host->addresses.entry[idx].weight,
-				get_host_cache_addr_expiry(tbuf, sizeof(tbuf), host, &host->addresses.entry[idx].addr));
+				host->addresses.entry[cnt].priority,
+				host->addresses.entry[cnt].weight,
+				get_host_cache_addr_expiry(tbuf, sizeof(tbuf), host, &host->addresses.entry[cnt].addr));
 		}
 	}
 	AST_LIST_TRAVERSE_SAFE_END;
-- 
GitLab