Index: channels/chan_sip.c
===================================================================
--- channels/chan_sip.c	(revision 168013)
+++ channels/chan_sip.c	(working copy)
@@ -1898,7 +1898,7 @@
 	struct timeval regtime;		/*!< Last successful registration time */
 	int callid_valid;		/*!< 0 means we haven't chosen callid for this registry yet. */
 	unsigned int ocseq;		/*!< Sequence number we got to for REGISTERs for this registry */
-	struct ast_dnsmgr_entry *dnsmgr;	/*!<  DNS refresh manager for register */
+	unsigned int needdns:1; /*!< If the initial dns lookup (transmit_register) has been made for this registration */
 	struct sockaddr_in us;		/*!< Who the server thinks we are */
 	int noncecount;			/*!< Nonce-count */
 	char lastmsg[256];		/*!< Last Message sent/received */
@@ -3208,7 +3208,13 @@
 		case ECONNREFUSED:      /* ICMP port unreachable */ 
 			res = XMIT_ERROR;	/* Don't bother with trying to transmit again */
 		}
+
+		if (p->registry && p->registry->regstate < REG_STATE_REGISTERED) {
+			AST_SCHED_DEL(sched, p->registry->timeout);
+			p->registry->timeout = ast_sched_add(sched, 1, sip_reg_timeout, p->registry);
+		}
 	}
+
 	if (res != len)
 		ast_log(LOG_WARNING, "sip_xmit of %p (len %d) to %s:%d returned %d: %s\n", data, len, ast_inet_ntoa(dst->sin_addr), ntohs(dst->sin_port), res, strerror(errno));
 
@@ -4972,7 +4978,6 @@
 	
 	ast_string_field_free_memory(reg);
 	ast_atomic_fetchadd_int(&regobjs, -1);
-	ast_dnsmgr_release(reg->dnsmgr);
 	ast_free(reg);
 }
 
@@ -10419,9 +10424,10 @@
 	if (!r)
 		return 0;
 
-	if (r->dnsmgr) {
-		/* If the registration has timed out, maybe the IP changed.  Force a refresh. */
-		ast_dnsmgr_refresh(r->dnsmgr);
+	{ /* If the registration has timed out and we haven't gotten a reply: force a refresh. */
+		char transport[MAXHOSTNAMELEN];
+		snprintf(transport, sizeof(transport), "_sip._%s", get_transport(r->transport)); /* have to use static get_transport function */
+		ast_get_ip_or_srv(&r->us, r->hostname, global_srvlookup ? transport : NULL);
 	}
 
 	ast_log(LOG_NOTICE, "   -- Registration for '%s@%s' timed out, trying again (Attempt #%d)\n", r->username, r->hostname, r->regattempts); 
@@ -10484,10 +10490,11 @@
 		return 0;
 	}
 
-	if (r->dnsmgr == NULL) {
+	if (r->needdns) {
 		char transport[MAXHOSTNAMELEN];
 		snprintf(transport, sizeof(transport), "_sip._%s", get_transport(r->transport)); /* have to use static get_transport function */
-		ast_dnsmgr_lookup(r->hostname, &r->us, &r->dnsmgr, sip_cfg.srvlookup ? transport : NULL);
+		ast_get_ip_or_srv(&r->us, r->hostname, global_srvlookup ? transport : NULL);
+		r->needdns = FALSE;
 	}
 
 	if (r->call) {	/* We have a registration */
@@ -10542,7 +10549,7 @@
 
 		/* Copy back Call-ID in case create_addr changed it */
 		ast_string_field_set(r, callid, p->callid);
-		if (!r->dnsmgr && r->portno) {
+		if (r->portno) {
 			p->sa.sin_port = htons(r->portno);
  			p->recv.sin_port = htons(r->portno);
 		} else {	/* Set registry port to the port set from the peer definition/srv or default */
@@ -14285,8 +14292,8 @@
 /*! \brief  Show SIP Registry (registrations with other SIP proxies */
 static char *sip_show_registry(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-#define FORMAT2 "%-30.30s %-6.6s %-12.12s  %8.8s %-20.20s %-25.25s\n"
-#define FORMAT  "%-30.30s %-6.6s %-12.12s  %8d %-20.20s %-25.25s\n"
+#define FORMAT2 "%-30.30s %-12.12s  %8.8s %-20.20s %-25.25s\n"
+#define FORMAT  "%-30.30s %-12.12s  %8d %-20.20s %-25.25s\n"
 	char host[80];
 	char tmpdat[256];
 	struct ast_tm tm;
@@ -14305,7 +14312,7 @@
 
 	if (a->argc != 3)
 		return CLI_SHOWUSAGE;
-	ast_cli(a->fd, FORMAT2, "Host", "dnsmgr", "Username", "Refresh", "State", "Reg.Time");
+	ast_cli(a->fd, FORMAT2, "Host", "Username", "Refresh", "State", "Reg.Time");
 	
 	ASTOBJ_CONTAINER_TRAVERSE(&regl, 1, do {
 		ASTOBJ_RDLOCK(iterator);
@@ -14315,7 +14322,7 @@
 			ast_strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm);
 		} else 
 			tmpdat[0] = '\0';
-		ast_cli(a->fd, FORMAT, host, (iterator->dnsmgr) ? "Y" : "N", iterator->username, iterator->refresh, regstate2str(iterator->regstate), tmpdat);
+		ast_cli(a->fd, FORMAT, host, iterator->username, iterator->refresh, regstate2str(iterator->regstate), tmpdat);
 		ASTOBJ_UNLOCK(iterator);
 		counter++;
 	} while(0));
