Index: /pjproject/trunk/pjlib-util/include/pjlib-util/config.h
===================================================================
--- /pjproject/trunk/pjlib-util/include/pjlib-util/config.h	(revision 1030)
+++ /pjproject/trunk/pjlib-util/include/pjlib-util/config.h	(revision 1031)
@@ -170,4 +170,13 @@
 
 
+/**
+ * Size of temporary pool buffer for parsing DNS packets in resolver.
+ *
+ * default: 4000
+ */
+#ifndef PJ_DNS_RESOLVER_TMP_BUF_SIZE
+#   define PJ_DNS_RESOLVER_TMP_BUF_SIZE		    4000
+#endif
+
 
 /* **************************************************************************
Index: /pjproject/trunk/pjlib-util/include/pjlib-util/dns.h
===================================================================
--- /pjproject/trunk/pjlib-util/include/pjlib-util/dns.h	(revision 1030)
+++ /pjproject/trunk/pjlib-util/include/pjlib-util/dns.h	(revision 1031)
@@ -26,5 +26,5 @@
  */
 #include <pjlib-util/types.h>
-
+#include <pj/sock.h>
 
 PJ_BEGIN_DECL
@@ -259,5 +259,6 @@
 	/** A Resource Data (PJ_DNS_TYPE_A, 1) */
 	struct a {
-	    pj_str_t	ip_addr;/**< IP host address string.		    */
+	    //pj_str_t	ip_addr;/**< IP host address string.		    */
+	    pj_in_addr	ip_addr;
 	} a;
 
@@ -280,4 +281,17 @@
     pj_dns_parsed_rr	*arr;	/**< Array of additional RR answer.	    */
 } pj_dns_parsed_packet;
+
+
+/**
+ * Option flags to be specified when calling #pj_dns_packet_dup() function.
+ * These flags can be combined with bitwise OR operation.
+ */
+enum pj_dns_dup_options
+{
+    PJ_DNS_NO_QD    = 1, /**< Do not duplicate the query section.	    */
+    PJ_DNS_NO_ANS   = 2, /**< Do not duplicate the answer section.	    */
+    PJ_DNS_NO_NS    = 4, /**< Do not duplicate the NS section.		    */
+    PJ_DNS_NO_AR    = 8  /**< Do not duplicate the additional rec section   */
+};
 
 
@@ -332,8 +346,10 @@
  * @param pool		The pool to allocate memory for the duplicated packet.
  * @param p		The DNS packet to be cloned.
+ * @param options	Option flags, from pj_dns_dup_options.
  * @param p_dst		Pointer to store the cloned DNS packet.
  */
 PJ_DECL(void) pj_dns_packet_dup(pj_pool_t *pool,
 				const pj_dns_parsed_packet*p,
+				unsigned options,
 				pj_dns_parsed_packet **p_dst);
 
Index: /pjproject/trunk/pjlib-util/src/pjlib-util/dns.c
===================================================================
--- /pjproject/trunk/pjlib-util/src/pjlib-util/dns.c	(revision 1030)
+++ /pjproject/trunk/pjlib-util/src/pjlib-util/dns.c	(revision 1031)
@@ -341,9 +341,5 @@
     /* Parse some well known records */
     if (rr->type == PJ_DNS_TYPE_A) {
-	pj_in_addr ip_addr;
-
-	pj_memcpy(&ip_addr, p, 4);
-	pj_strdup2(pool, &rr->rdata.a.ip_addr, pj_inet_ntoa(ip_addr));
-
+	pj_memcpy(&rr->rdata.a.ip_addr, p, 4);
 	p += 4;
 
@@ -588,5 +584,5 @@
 			 pool, &dst->rdata.srv.target);
     } else if (src->type == PJ_DNS_TYPE_A) {
-	pj_strdup(pool, &dst->rdata.a.ip_addr, &src->rdata.a.ip_addr);
+	dst->rdata.a.ip_addr.s_addr =  src->rdata.a.ip_addr.s_addr;
     } else if (src->type == PJ_DNS_TYPE_CNAME) {
 	pj_strdup(pool, &dst->rdata.cname.name, &src->rdata.cname.name);
@@ -603,4 +599,5 @@
 PJ_DEF(void) pj_dns_packet_dup(pj_pool_t *pool,
 			       const pj_dns_parsed_packet*p,
+			       unsigned options,
 			       pj_dns_parsed_packet **p_dst)
 {
@@ -631,5 +628,5 @@
 
     /* Copy query section */
-    if (p->hdr.qdcount) {
+    if (p->hdr.qdcount && (options & PJ_DNS_NO_QD)==0) {
 	dst->q = pj_pool_alloc(pool, p->hdr.qdcount * 
 				     sizeof(pj_dns_parsed_query));
@@ -642,5 +639,5 @@
 
     /* Copy answer section */
-    if (p->hdr.anscount) {
+    if (p->hdr.anscount && (options & PJ_DNS_NO_ANS)==0) {
 	dst->ans = pj_pool_alloc(pool, p->hdr.anscount * 
 				       sizeof(pj_dns_parsed_rr));
@@ -653,5 +650,5 @@
 
     /* Copy NS section */
-    if (p->hdr.nscount) {
+    if (p->hdr.nscount && (options & PJ_DNS_NO_NS)==0) {
 	dst->ns = pj_pool_alloc(pool, p->hdr.nscount * 
 				      sizeof(pj_dns_parsed_rr));
@@ -664,5 +661,5 @@
 
     /* Copy additional info section */
-    if (p->hdr.arcount) {
+    if (p->hdr.arcount && (options & PJ_DNS_NO_AR)==0) {
 	dst->arr = pj_pool_alloc(pool, p->hdr.arcount * 
 				       sizeof(pj_dns_parsed_rr));
Index: /pjproject/trunk/pjlib-util/src/pjlib-util/dns_dump.c
===================================================================
--- /pjproject/trunk/pjlib-util/src/pjlib-util/dns_dump.c	(revision 1030)
+++ /pjproject/trunk/pjlib-util/src/pjlib-util/dns_dump.c	(revision 1031)
@@ -116,7 +116,6 @@
 		  rr->rdata.cname.name.ptr));
     } else if (rr->type == PJ_DNS_TYPE_A) {
-	PJ_LOG(3,(THIS_FILE, "    IP address: %.*s",
-		  (int)rr->rdata.a.ip_addr.slen,
-		  rr->rdata.a.ip_addr.ptr));
+	PJ_LOG(3,(THIS_FILE, "    IP address: %s",
+		  pj_inet_ntoa(rr->rdata.a.ip_addr)));
     }
 }
Index: /pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c
===================================================================
--- /pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c	(revision 1030)
+++ /pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c	(revision 1031)
@@ -52,4 +52,5 @@
 #define RES_BUF_SZ	    PJ_DNS_RESOLVER_RES_BUF_SIZE
 #define UDPSZ		    PJ_DNS_RESOLVER_MAX_UDP_SIZE
+#define TMP_SZ		    PJ_DNS_RESOLVER_TMP_BUF_SIZE
 
 
@@ -162,5 +163,5 @@
     pj_bool_t		 own_ioqueue;	/**< Do we own ioqueue?		    */
     pj_ioqueue_t	*ioqueue;	/**< Ioqueue instance.		    */
-    char		 tmp_pool[1500];/**< Temporary pool buffer.	    */
+    char		 tmp_pool[TMP_SZ];/**< Temporary pool buffer.	    */
 
     /* Socket */
@@ -994,9 +995,14 @@
     }
 
-    /* Duplicate the packet */
+    /* Duplicate the packet.
+     * We don't need to keep the query, NS, and AR sections from the packet,
+     * so exclude from duplication.
+     */
     res_pool = pj_pool_create_on_buf("respool", cache->buf, sizeof(cache->buf));
     PJ_TRY {
 	cache->pkt = NULL;
-	pj_dns_packet_dup(res_pool, pkt, &cache->pkt);
+	pj_dns_packet_dup(res_pool, pkt, 
+			  PJ_DNS_NO_QD | PJ_DNS_NO_NS | PJ_DNS_NO_AR,
+			  &cache->pkt);
     }
     PJ_CATCH_ANY {
@@ -1223,8 +1229,4 @@
 	}
     }
-
-    /* We don't need NS and query section in the packet, so trim them. */
-    dns_pkt->hdr.qdcount = 0;
-    dns_pkt->hdr.nscount = 0;
 
     /* Save/update response cache. */
Index: /pjproject/trunk/pjsip/src/pjsip/sip_resolve.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_resolve.c	(revision 1030)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_resolve.c	(revision 1031)
@@ -536,5 +536,5 @@
 	    if (pj_stricmp(&rr->name, &query->srv[j].target_name)==0) {
 		unsigned cnt = query->srv[j].addr_cnt;
-		query->srv[j].addr[cnt] = pj_inet_addr(&rr->rdata.a.ip_addr);
+		query->srv[j].addr[cnt].s_addr = rr->rdata.a.ip_addr.s_addr;
 		++query->srv[j].addr_cnt;
 		++query->host_resolved;
@@ -778,13 +778,12 @@
 		unsigned j;
 
-		query->srv[i].addr[query->srv[i].addr_cnt++] =
-		    pj_inet_addr(&pkt->ans[0].rdata.a.ip_addr);
+		query->srv[i].addr[query->srv[i].addr_cnt++].s_addr =
+		    pkt->ans[0].rdata.a.ip_addr.s_addr;
 
 		PJ_LOG(5,(query->objname, 
-			  "DNS A for %.*s: %.*s",
+			  "DNS A for %.*s: %s",
 			  (int)query->srv[i].target_name.slen, 
 			  query->srv[i].target_name.ptr,
-			  (int)pkt->ans[0].rdata.a.ip_addr.slen,
-			  pkt->ans[0].rdata.a.ip_addr.ptr));
+			  pj_inet_ntoa(pkt->ans[0].rdata.a.ip_addr)));
 
 		/* Check for multiple IP addresses */
@@ -792,13 +791,12 @@
 			    query->srv[i].addr_cnt < ADDR_MAX_COUNT; ++j)
 		{
-		    query->srv[i].addr[query->srv[i].addr_cnt++] = 
-			pj_inet_addr(&pkt->ans[j].rdata.a.ip_addr);
+		    query->srv[i].addr[query->srv[i].addr_cnt++].s_addr = 
+			pkt->ans[j].rdata.a.ip_addr.s_addr;
 
 		    PJ_LOG(5,(query->objname, 
-			      "Additional DNS A for %.*s: %.*s",
+			      "Additional DNS A for %.*s: %s",
 			      (int)query->srv[i].target_name.slen, 
 			      query->srv[i].target_name.ptr,
-			      (int)pkt->ans[j].rdata.a.ip_addr.slen,
-			      pkt->ans[j].rdata.a.ip_addr.ptr));
+			      pj_inet_ntoa(pkt->ans[j].rdata.a.ip_addr)));
 		}
 	    }
