[asterisk-commits] jpeeler: branch jpeeler/sip-dnsmgr r111810 - /team/jpeeler/sip-dnsmgr/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 28 14:34:17 CDT 2008


Author: jpeeler
Date: Fri Mar 28 14:34:17 2008
New Revision: 111810

URL: http://svn.digium.com/view/asterisk?view=rev&rev=111810
Log:
ast_dnsmgr_entry modified to have sockaddr_in instead of just in_addr

Modified:
    team/jpeeler/sip-dnsmgr/main/dnsmgr.c

Modified: team/jpeeler/sip-dnsmgr/main/dnsmgr.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/sip-dnsmgr/main/dnsmgr.c?view=diff&rev=111810&r1=111809&r2=111810
==============================================================================
--- team/jpeeler/sip-dnsmgr/main/dnsmgr.c (original)
+++ team/jpeeler/sip-dnsmgr/main/dnsmgr.c Fri Mar 28 14:34:17 2008
@@ -45,11 +45,9 @@
 
 struct ast_dnsmgr_entry {
 	/*! where we will store the resulting address */
-	struct in_addr *result;
+	struct sockaddr_in *result;
 	/*! the last result, used to check if address has changed */
-	struct in_addr last;
-	unsigned short *result_portno;
-	unsigned short last_portno;
+	struct sockaddr_in last;
 	char service[MAXHOSTNAMELEN];
 	int dnssrv:1;
 	/*! Set to 1 if the entry changes */
@@ -88,7 +86,7 @@
 	if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, sizeof(*entry) + strlen(name))))
 		return NULL;
 
-	entry->result = result;
+	entry->result->sin_addr = *result;
 	ast_mutex_init(&entry->lock);
 	strcpy(entry->name, name);
 	memcpy(&entry->last, result, sizeof(entry->last));
@@ -109,14 +107,11 @@
 	if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, sizeof(*entry) + strlen(name))))
 		return NULL;
 
-	entry->result = &result->sin_addr;
-	entry->result_portno = &result->sin_port;
+	entry->result = result;
 	ast_mutex_init(&entry->lock);
 	strcpy(entry->name, name);
 	strcpy(entry->service, service);
-	memcpy(&entry->last, &result->sin_addr, sizeof(entry->last));
-	ast_log(LOG_DEBUG, "******************* entry->last_portno@%p entry->last@%p", &entry->last_portno, &entry->last);
-	entry->last_portno = result->sin_port;
+	memcpy(&entry->last, &result, sizeof(entry->last));
 	entry->dnssrv = 1;
 
 	AST_RWLIST_WRLOCK(&entry_list);
@@ -245,23 +240,16 @@
 		if (srv_ret > 0) {
 			if ((hp = ast_gethostbyname(realhostname, &ahp))) {
 				memcpy(&tmp, hp->h_addr, sizeof(tmp));
-				if (tmp.s_addr != entry->last.s_addr || real_portno != ntohs(entry->last_portno)) {
-
-					if (tmp.s_addr != entry->last.s_addr)
-						ast_log(LOG_DEBUG, "tmp != entry\n");
-					if (real_portno != ntohs(entry->last_portno))
-						ast_log(LOG_DEBUG, "real_portno (%d) != entry->last_portno (%d)\n", real_portno, ntohs(entry->last_portno));
-
-					ast_copy_string(iabuf, ast_inet_ntoa(entry->last), sizeof(iabuf));
+				if (tmp.s_addr != entry->last.sin_addr.s_addr || real_portno != ntohs(entry->last.sin_port)) {
+					ast_copy_string(iabuf, ast_inet_ntoa(entry->last.sin_addr), sizeof(iabuf));
 					ast_copy_string(iabuf2, ast_inet_ntoa(tmp), sizeof(iabuf2));
 					ast_log(LOG_NOTICE, "dnssrv: host '%s' changed from %s:%d to %s:%d\n", 
-						entry->name, iabuf, ntohs(entry->last_portno), iabuf2, real_portno);
-
-					memcpy(entry->result, hp->h_addr, sizeof(entry->result));
-					memcpy(&entry->last, hp->h_addr, sizeof(entry->last));
-					*entry->result_portno = htons((unsigned short)real_portno);
-					entry->last_portno = htons((unsigned short)real_portno);
-					ast_log(LOG_DEBUG, "Verifying that new port has been accounted for, new port = %d\n", ntohs(entry->last_portno));
+						entry->name, iabuf, ntohs(entry->last.sin_port), iabuf2, real_portno);
+
+					memcpy(&entry->result->sin_addr, hp->h_addr, sizeof(entry->result->sin_addr));
+					memcpy(&entry->last.sin_addr, hp->h_addr, sizeof(entry->last.sin_addr));
+					entry->result->sin_port = htons((unsigned short)real_portno);
+					entry->last.sin_port = htons((unsigned short)real_portno);
 					changed = entry->changed = 1;
 				}
 			}
@@ -269,8 +257,8 @@
 	} else if ((hp = ast_gethostbyname(entry->name, &ahp))) {
 		/* check to see if it has changed, do callback if requested (where de callback is defined ????) */
 		memcpy(&tmp, hp->h_addr, sizeof(tmp));
-		if (tmp.s_addr != entry->last.s_addr) {
-			ast_copy_string(iabuf, ast_inet_ntoa(entry->last), sizeof(iabuf));
+		if (tmp.s_addr != entry->last.sin_addr.s_addr) {
+			ast_copy_string(iabuf, ast_inet_ntoa(entry->last.sin_addr), sizeof(iabuf));
 			ast_copy_string(iabuf2, ast_inet_ntoa(tmp), sizeof(iabuf2));
 			ast_log(LOG_NOTICE, "host '%s' changed from %s to %s\n", 
 				entry->name, iabuf, iabuf2);




More information about the asterisk-commits mailing list