[asterisk-commits] file: branch 1.2 r68368 - /branches/1.2/dnsmgr.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Jun 7 16:59:05 MST 2007


Author: file
Date: Thu Jun  7 18:59:04 2007
New Revision: 68368

URL: http://svn.digium.com/view/asterisk?view=rev&rev=68368
Log:
Do a DNS lookup immediately upon calling the dnsmgr function, don't wait until a refresh happens. (issue #9097 reported by plack)

Modified:
    branches/1.2/dnsmgr.c

Modified: branches/1.2/dnsmgr.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/dnsmgr.c?view=diff&rev=68368&r1=68367&r2=68368
==============================================================================
--- branches/1.2/dnsmgr.c (original)
+++ branches/1.2/dnsmgr.c Thu Jun  7 18:59:04 2007
@@ -112,6 +112,9 @@
 
 int ast_dnsmgr_lookup(const char *name, struct in_addr *result, struct ast_dnsmgr_entry **dnsmgr)
 {
+	struct ast_hostent ahp;
+	struct hostent *hp;
+
 	if (ast_strlen_zero(name) || !result || !dnsmgr)
 		return -1;
 
@@ -126,21 +129,18 @@
 	if (inet_aton(name, result))
 		return 0;
 
-	/* if the manager is disabled, do a direct lookup and return the result,
-	   otherwise register a managed lookup for the name */
-	if (!enabled) {
-		struct ast_hostent ahp;
-		struct hostent *hp;
-
-		if ((hp = ast_gethostbyname(name, &ahp)))
-			memcpy(result, hp->h_addr, sizeof(result));
+	/* do a lookup now but add a manager so it will automagically get updated in the background */
+	if ((hp = ast_gethostbyname(name, &ahp)))
+		memcpy(result, hp->h_addr, sizeof(result));
+
+	/* if dnsmgr is not enable don't bother adding an entry */
+	if (!enabled)
 		return 0;
-	} else {
-		if (option_verbose > 2)
-			ast_verbose(VERBOSE_PREFIX_2 "adding manager for '%s'\n", name);
-		*dnsmgr = ast_dnsmgr_get(name, result);
-		return !*dnsmgr;
-	}
+	
+	if (option_verbose > 2)
+		ast_verbose(VERBOSE_PREFIX_2 "adding manager for '%s'\n", name);
+	*dnsmgr = ast_dnsmgr_get(name, result);
+	return !*dnsmgr;
 }
 
 static void *do_refresh(void *data)



More information about the asterisk-commits mailing list