You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2011/08/11 01:22:53 UTC

svn commit: r1156401 - in /trafficserver/traffic/trunk: ./ iocore/dns/ iocore/eventsystem/ iocore/hostdb/ lib/ts/ proxy/ proxy/http/ proxy/logging/

Author: amc
Date: Wed Aug 10 23:22:53 2011
New Revision: 1156401

URL: http://svn.apache.org/viewvc?rev=1156401&view=rev
Log:
TS-908: IPv6 HostDB

Modified:
    trafficserver/traffic/trunk/CHANGES
    trafficserver/traffic/trunk/iocore/dns/DNS.cc
    trafficserver/traffic/trunk/iocore/dns/DNSConnection.cc
    trafficserver/traffic/trunk/iocore/eventsystem/I_Continuation.h
    trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc
    trafficserver/traffic/trunk/iocore/hostdb/I_HostDBProcessor.h
    trafficserver/traffic/trunk/iocore/hostdb/P_HostDB.h
    trafficserver/traffic/trunk/iocore/hostdb/P_HostDBProcessor.h
    trafficserver/traffic/trunk/iocore/hostdb/P_MultiCache.h
    trafficserver/traffic/trunk/lib/ts/ink_inet.h
    trafficserver/traffic/trunk/proxy/InkAPI.cc
    trafficserver/traffic/trunk/proxy/http/HttpSM.cc
    trafficserver/traffic/trunk/proxy/http/HttpTransact.cc
    trafficserver/traffic/trunk/proxy/logging/LogCollationClientSM.cc

Modified: trafficserver/traffic/trunk/CHANGES
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/CHANGES?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/CHANGES (original)
+++ trafficserver/traffic/trunk/CHANGES Wed Aug 10 23:22:53 2011
@@ -3,6 +3,8 @@
 Changes with Apache Traffic Server 3.1.0
   *) [TS-911] Remove unecessary lock in HTTP accept.
 
+  *) [TS-908] HostDB now stores IPv6 addresses.
+
   *) [TS-813] fix http_ui /stat/ to response with content type
 
   *) [TS-849] fix some variables for traffic_line -s setting

Modified: trafficserver/traffic/trunk/iocore/dns/DNS.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/dns/DNS.cc?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/dns/DNS.cc (original)
+++ trafficserver/traffic/trunk/iocore/dns/DNS.cc Wed Aug 10 23:22:53 2011
@@ -1534,7 +1534,7 @@ dns_process(DNSHandler *handler, HostEnt
         } else {
           int nn;
           buf->ent.h_length = n;
-          buf->ent.h_addrtype = C_IN;
+          buf->ent.h_addrtype = T_A == type ? AF_INET : AF_INET6;
           buf->ent.h_name = (char *) bp;
           nn = strlen((char *) bp) + 1;
           Debug("dns", "received %s name = %s", QtypeName(type), bp);

Modified: trafficserver/traffic/trunk/iocore/dns/DNSConnection.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/dns/DNSConnection.cc?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/dns/DNSConnection.cc (original)
+++ trafficserver/traffic/trunk/iocore/dns/DNSConnection.cc Wed Aug 10 23:22:53 2011
@@ -127,6 +127,17 @@ DNSConnection::connect(sockaddr const* a
 
   if (opt._bind_random_port) {
     int retries = 0;
+    ts_ip_endpoint bind_addr;
+    size_t bind_size = 0;
+    memset(&bind_addr, 0, sizeof bind_addr);
+    bind_addr.sa.sa_family = af;
+    if (AF_INET6 == af) {
+      bind_addr.sin6.sin6_addr = in6addr_any;
+      bind_size = sizeof bind_addr.sin6;
+    } else {
+      bind_addr.sin.sin_addr.s_addr = INADDR_ANY;
+      bind_size = sizeof bind_addr.sin;
+    }
     while (retries++ < 10000) {
       ip_port_text_buffer b;
       uint32_t p = generator.random();

Modified: trafficserver/traffic/trunk/iocore/eventsystem/I_Continuation.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/eventsystem/I_Continuation.h?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/eventsystem/I_Continuation.h (original)
+++ trafficserver/traffic/trunk/iocore/eventsystem/I_Continuation.h Wed Aug 10 23:22:53 2011
@@ -119,6 +119,10 @@ public:
 
   */
   ProxyMutexPtr mutex;
+  /** Thread ID of thread currently executing this continuation.
+      Set to zero when not being executed.
+   */
+  uint32_t in_thread;
 
   /**
     Link to other continuations.
@@ -194,7 +198,8 @@ Continuation::Continuation(ProxyMutex * 
 #ifdef DEBUG
     handler_name(NULL),
 #endif
-    mutex(amutex)
+             mutex(amutex),
+             in_thread(0)
 { }
 
 #endif /*_Continuation_h_*/

Modified: trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc (original)
+++ trafficserver/traffic/trunk/iocore/hostdb/HostDB.cc Wed Aug 10 23:22:53 2011
@@ -83,6 +83,29 @@ corrupt_debugging_callout(HostDBInfo * e
   return -1;
 }
 
+static inline bool
+is_addr_valid(
+  uint8_t af, ///< Address family (format of data)
+  void* ptr ///< Raw address data (not a sockaddr variant!)
+) {
+  return 
+    (AF_INET == af && INADDR_ANY != *(reinterpret_cast<in_addr_t*>(ptr)))
+    || (AF_INET6 == af && !IN6_IS_ADDR_UNSPECIFIED(ptr))
+    ;
+}
+
+static inline void
+ip_addr_set(
+  sockaddr* ip, ///< Target storage, sockaddr compliant.
+  uint8_t af, ///< Address format.
+  void* ptr ///< Raw address data
+) {
+  if (AF_INET6 == af)
+    ink_inet_ip6_set(ip, *static_cast<in6_addr*>(ptr));
+  else if (AF_INET == af)
+    ink_inet_ip4_set(ip, *static_cast<in_addr_t*>(ptr));
+  else ink_inet_invalidate(ip);
+}
 
 inline void
 hostdb_cont_free(HostDBContinuation * cont)
@@ -151,7 +174,7 @@ HostDBCache::rebuild_callout(HostDBInfo 
     for (int i = 0; i < rr->good; i++) {
       if (!valid_heap_pointer(((char *) &rr->info[i + 1]) - 1))
         return -1;
-      if (!rr->info[i].ip())
+      if (!ink_inet_is_ip(rr->info[i].ip()))
         return corrupt_debugging_callout(e, r);
       if (rr->info[i].md5_high != e->md5_high ||
           rr->info[i].md5_low != e->md5_low || rr->info[i].md5_low_low != e->md5_low_low)
@@ -185,11 +208,11 @@ struct HostDBTestRR: public Continuation
       printf("HostDBTestRR: %d outstanding %d succcess %d failure\n", outstanding, success, failure);
     }
     if (event == EVENT_HOST_DB_LOOKUP) {
-      outstanding--;
+      --outstanding;
       if (e)
-        success++;
+        ++success;
       else
-        failure++;
+        ++failure;
     }
     if (in)
       return EVENT_CONT;
@@ -423,9 +446,11 @@ HostDBProcessor::start(int)
 
 
 void
-HostDBContinuation::init(char *hostname, int len,
-                         int aip, int aport, INK_MD5 & amd5, Continuation * cont, void *pDS, bool is_srv, int timeout)
-{
+HostDBContinuation::init(
+  char *hostname, int len,
+  sockaddr const* aip,
+  INK_MD5 & amd5, Continuation * cont, void *pDS, bool is_srv, int timeout
+) {
   if (hostname) {
     memcpy(name, hostname, len);
     name[len] = 0;
@@ -434,8 +459,7 @@ HostDBContinuation::init(char *hostname,
   dns_lookup_timeout = timeout;
   namelen = len;
   is_srv_lookup = is_srv;
-  ip = aip;
-  port = aport;
+  ink_inet_copy(&ip.sa, aip);
   md5 = amd5;
   mutex = hostDB.lock_for_bucket((int) (fold_md5(md5) % hostDB.buckets));
   m_pDS = pDS;
@@ -510,7 +534,8 @@ reply_to_cont(Continuation * cont, HostD
         ink_assert(!"missing round-robin");
         goto Lerror;
       }
-      Debug("hostdb", "RR of %d with %d good, 1st IP = %X", r->rr()->n, r->rr()->good, r->ip());
+      ip_text_buffer ipb;
+      Debug("hostdb", "RR of %d with %d good, 1st IP = %s", r->rr()->n, r->rr()->good, ink_inet_ntop(r->ip(), ipb, sizeof ipb));
     }
     if (r->is_srv && r->srv_count) {
       cont->handleEvent(EVENT_SRV_LOOKUP, r);
@@ -540,7 +565,7 @@ Ldelete:
 
 
 HostDBInfo *
-probe(ProxyMutex *mutex, INK_MD5 & md5, char *hostname, int len, int ip, int port, void *pDS, bool ignore_timeout,
+probe(ProxyMutex *mutex, INK_MD5 & md5, char *hostname, int len, sockaddr const* ip, void *pDS, bool ignore_timeout,
       bool is_srv_lookup)
 {
   ink_debug_assert(this_ethread() == hostDB.lock_for_bucket((int) (fold_md5(md5) % hostDB.buckets))->thread_holding);
@@ -590,7 +615,7 @@ probe(ProxyMutex *mutex, INK_MD5 & md5, 
         r->refresh_ip();
         if (!is_dotted_form_hostname(hostname)) {
           HostDBContinuation *c = hostDBContAllocator.alloc();
-          c->init(hostname, len, ip, port, md5, NULL, pDS, is_srv_lookup, 0);
+          c->init(hostname, len, ip, md5, NULL, pDS, is_srv_lookup, 0);
           c->do_dns();
         }
       }
@@ -636,13 +661,15 @@ HostDBContinuation::insert(unsigned int 
 //
 Action *
 HostDBProcessor::getby(Continuation * cont,
-                       char *hostname, int len, int port, unsigned int ip, bool aforce_dns, int dns_lookup_timeout)
+                       char *hostname, int len, sockaddr const* ip, bool aforce_dns, int dns_lookup_timeout)
 {
   INK_MD5 md5;
   char *pServerLine = 0;
   void *pDS = 0;
   EThread *thread = this_ethread();
   ProxyMutex *mutex = thread->mutex;
+  unsigned short port = ink_inet_port_cast(ip);
+  ip_text_buffer ipb;
 
   HOSTDB_INCREMENT_DYN_STAT(hostdb_total_lookups_stat);
 
@@ -678,17 +705,16 @@ HostDBProcessor::getby(Continuation * co
       len = strlen(hostname);
     make_md5(md5, hostname, len, port, pServerLine);
   } else {
-
     // INK_MD5 the ip, pad on both sizes with 0's
     // so that it does not intersect the string space
     //
-    // suvasv: Changed from this
-    //    uint64_t dummy = ip << 16;
-    //  to uint64_t dummy = ip*64*1024 for bug INKqa10029.
-    //  Problem was that ip << 16 would not work for architectures with
-    //  a different byte order. This takes cares of all byte orders.
-    uint64_t dummy = ((uint64_t) ip) * 64 * 1024;
-    md5.encodeBuffer((char *) &dummy, 8);
+    uint8_t buff[INK_IP6_SIZE+4];
+    memset(buff, 0, sizeof(buff));
+    if (ink_inet_is_ip4(ip))
+      memcpy(buff+2, &ink_inet_ip4_addr_cast(ip), sizeof(in_addr_t));
+    else if (ink_inet_is_ip6(ip))
+      memcpy(buff+2, &ink_inet_ip6_addr_cast(ip), sizeof(in6_addr));
+    md5.encodeBuffer(buff, sizeof buff);
   }
 
   // Attempt to find the result in-line, for level 1 hits
@@ -704,22 +730,30 @@ HostDBProcessor::getby(Continuation * co
     // If we can get the lock and a level 1 probe succeeds, return
     //
     if (lock && lock2) {
-      HostDBInfo *r = probe(bmutex, md5, hostname, len, ip, port, pDS);
+      HostDBInfo *r = probe(bmutex, md5, hostname, len, ip, pDS);
       if (r) {
-        Debug("hostdb", "immediate answer for %s", hostname ? hostname : "<addr>");
+        Debug("hostdb", "immediate answer for %s",
+          hostname ? hostname 
+          : ink_inet_is_ip(ip) ? ink_inet_ntop(ip, ipb, sizeof ipb)
+          : "<null>"
+        );
         HOSTDB_INCREMENT_DYN_STAT(hostdb_total_hits_stat);
         reply_to_cont(cont, r);
         return ACTION_RESULT_DONE;
       }
     }
   }
-  Debug("hostdb", "delaying force %d answer for %s", aforce_dns, hostname);
+  Debug("hostdb", "delaying force %d answer for %s", aforce_dns,
+    hostname ? hostname 
+    : ink_inet_is_ip(ip) ? ink_inet_ntop(ip, ipb, sizeof ipb)
+    : "<null>"
+  );
 
 Lretry:
   // Otherwise, create a continuation to do a deeper probe in the background
   //
   HostDBContinuation *c = hostDBContAllocator.alloc();
-  c->init(hostname, len, ip, port, md5, cont, pDS, false, dns_lookup_timeout);
+  c->init(hostname, len, ip, md5, cont, pDS, false, dns_lookup_timeout);
   c->action = cont;
   c->force_dns = aforce_dns;
   SET_CONTINUATION_HANDLER(c, (HostDBContHandler) & HostDBContinuation::probeEvent);
@@ -745,6 +779,9 @@ HostDBProcessor::getbyname_re(Continuati
   bool force_dns = false;
   EThread *thread = this_ethread();
   ProxyMutex *mutex = thread->mutex;
+  sockaddr_in ip;
+
+  ink_inet_ip4_set(&ip, INADDR_ANY, port);
 
   if (flags & HOSTDB_FORCE_DNS_ALWAYS)
     force_dns = true;
@@ -753,7 +790,7 @@ HostDBProcessor::getbyname_re(Continuati
     if (force_dns)
       HOSTDB_INCREMENT_DYN_STAT(hostdb_re_dns_on_reload_stat);
   }
-  return getby(cont, ahostname, len, port, 0, force_dns);
+  return getby(cont, ahostname, len, ink_inet_sa_cast(&ip), force_dns);
 }
 
 
@@ -785,6 +822,9 @@ HostDBProcessor::getSRVbyname_imm(Contin
     return ACTION_RESULT_DONE;
   }
 
+  sockaddr_in ip;
+  ink_inet_ip4_set(&ip, INADDR_ANY, port);
+
   if (!len)
     len = strlen(hostname);
 
@@ -798,7 +838,7 @@ HostDBProcessor::getSRVbyname_imm(Contin
 
     // If we can get the lock and a level 1 probe succeeds, return
     if (lock) {
-      HostDBInfo *r = probe(bucket_mutex, md5, hostname, len, 1, port, pDS, false, true);
+      HostDBInfo *r = probe(bucket_mutex, md5, hostname, len, ink_inet_sa_cast(&ip), pDS, false, true);
       if (r) {
         Debug("hostdb", "immediate SRV answer for %s from hostdb", hostname);
         Debug("dns_srv", "immediate SRV answer for %s from hostdb", hostname);
@@ -813,7 +853,7 @@ HostDBProcessor::getSRVbyname_imm(Contin
 
   // Otherwise, create a continuation to do a deeper probe in the background
   HostDBContinuation *c = hostDBContAllocator.alloc();
-  c->init(hostname, len, 0, port, md5, cont, pDS, true, dns_lookup_timeout);
+  c->init(hostname, len, ink_inet_sa_cast(&ip), md5, cont, pDS, true, dns_lookup_timeout);
   c->force_dns = force_dns;
   SET_CONTINUATION_HANDLER(c, (HostDBContHandler) & HostDBContinuation::probeEvent);
 
@@ -837,6 +877,9 @@ HostDBProcessor::getbyname_imm(Continuat
   bool force_dns = false;
   EThread *thread = cont->mutex->thread_holding;
   ProxyMutex *mutex = thread->mutex;
+  sockaddr_in ip_store;
+  sockaddr* ip = ink_inet_sa_cast(&ip_store);
+  ink_inet_ip4_set(ip, INADDR_ANY, port);
 
   if (flags & HOSTDB_FORCE_DNS_ALWAYS)
     force_dns = true;
@@ -887,7 +930,7 @@ HostDBProcessor::getbyname_imm(Continuat
 
     // If we can get the lock and a level 1 probe succeeds, return
     if (lock) {
-      HostDBInfo *r = probe(bucket_mutex, md5, hostname, len, 0, port, pDS);
+      HostDBInfo *r = probe(bucket_mutex, md5, hostname, len, ip, pDS);
       if (r) {
         Debug("hostdb", "immediate answer for %s", hostname ? hostname : "<addr>");
         HOSTDB_INCREMENT_DYN_STAT(hostdb_total_hits_stat);
@@ -901,7 +944,7 @@ HostDBProcessor::getbyname_imm(Continuat
 
   // Otherwise, create a continuation to do a deeper probe in the background
   HostDBContinuation *c = hostDBContAllocator.alloc();
-  c->init(hostname, len, 0, port, md5, cont, pDS, false, dns_lookup_timeout);
+  c->init(hostname, len, ip, md5, cont, pDS, false, dns_lookup_timeout);
   c->force_dns = force_dns;
   SET_CONTINUATION_HANDLER(c, (HostDBContHandler) & HostDBContinuation::probeEvent);
 
@@ -912,14 +955,14 @@ HostDBProcessor::getbyname_imm(Continuat
 
 
 static void
-do_setby(HostDBInfo * r, HostDBApplicationInfo * app, char *hostname, unsigned int ip)
+do_setby(HostDBInfo * r, HostDBApplicationInfo * app, char *hostname, sockaddr const* ip)
 {
   HostDBRoundRobin *rr = r->rr();
 
   if (rr) {
     ink_assert(hostname);
     for (int i = 0; i < rr->n; i++) {
-      if (rr->info[i].ip() == ip) {
+      if (0 == ink_inet_cmp(rr->info[i].ip(), ip)) {
         Debug("hostdb", "immediate setby for %s", hostname ? hostname : "<addr>");
         rr->info[i].app.allotment.application1 = app->allotment.application1;
         rr->info[i].app.allotment.application2 = app->allotment.application2;
@@ -927,7 +970,7 @@ do_setby(HostDBInfo * r, HostDBApplicati
       }
     }
   } else {
-    if (r->reverse_dns || (!r->round_robin && r->ip() == ip)) {
+    if (r->reverse_dns || (!r->round_robin && ink_inet_eq(r->ip(), ip))) {
       Debug("hostdb", "immediate setby for %s", hostname ? hostname : "<addr>");
       r->app.allotment.application1 = app->allotment.application1;
       r->app.allotment.application2 = app->allotment.application2;
@@ -937,12 +980,13 @@ do_setby(HostDBInfo * r, HostDBApplicati
 
 
 void
-HostDBProcessor::setby(char *hostname, int len, int port, unsigned int ip, HostDBApplicationInfo * app)
+HostDBProcessor::setby(char *hostname, int len, sockaddr const* ip, HostDBApplicationInfo * app)
 {
   if (!hostdb_enable)
     return;
 
   INK_MD5 md5;
+  unsigned short port = ink_inet_port_cast(ip);
 
   // if it is by name, INK_MD5 the name
   //
@@ -951,18 +995,16 @@ HostDBProcessor::setby(char *hostname, i
       len = strlen(hostname);
     make_md5(md5, hostname, len, port);
   } else {
-
     // INK_MD5 the ip, pad on both sizes with 0's
     // so that it does not intersect the string space
     //
-
-    // suvasv: Changed from this
-    //    uint64_t dummy = ip << 16;
-    //  to uint64_t dummy = ip*64*1024 for bug INKqa10029.
-    //  Problem was that ip << 16 would not work for architectures with
-    //  a different byte order. This takes cares of all byte orders.
-    uint64_t dummy = ((uint64_t) ip) * 64 * 1024;
-    md5.encodeBuffer((char *) &dummy, 8);
+    uint8_t buff[INK_IP6_SIZE+4];
+    memset(buff, 0, sizeof(buff));
+    if (ink_inet_is_ip4(ip))
+      memcpy(buff+2, &ink_inet_ip4_addr_cast(ip), sizeof(in_addr_t));
+    else if (ink_inet_is_ip6(ip))
+      memcpy(buff+2, &ink_inet_ip6_addr_cast(ip), sizeof(in6_addr));
+    md5.encodeBuffer(buff, sizeof buff);
   }
 
   // Attempt to find the result in-line, for level 1 hits
@@ -972,7 +1014,7 @@ HostDBProcessor::setby(char *hostname, i
   MUTEX_TRY_LOCK(lock, mutex, thread);
 
   if (lock) {
-    HostDBInfo *r = probe(mutex, md5, hostname, len, ip, port, 0);
+    HostDBInfo *r = probe(mutex, md5, hostname, len, ip, 0);
     if (r)
       do_setby(r, app, hostname, ip);
     return;
@@ -980,7 +1022,7 @@ HostDBProcessor::setby(char *hostname, i
   // Create a continuation to do a deaper probe in the background
 
   HostDBContinuation *c = hostDBContAllocator.alloc();
-  c->init(hostname, len, ip, port, md5, NULL);
+  c->init(hostname, len, ip, md5, NULL);
   c->app.allotment.application1 = app->allotment.application1;
   c->app.allotment.application2 = app->allotment.application2;
   SET_CONTINUATION_HANDLER(c, (HostDBContHandler) & HostDBContinuation::setbyEvent);
@@ -993,17 +1035,17 @@ HostDBContinuation::setbyEvent(int event
 {
   NOWARN_UNUSED(event);
   NOWARN_UNUSED(e);
-  HostDBInfo *r = probe(mutex, md5, name, namelen, ip, port, 0);
+  HostDBInfo *r = probe(mutex, md5, name, namelen, &ip.sa, 0);
 
   if (r)
-    do_setby(r, &app, name, ip);
+    do_setby(r, &app, name, &ip.sa);
   hostdb_cont_free(this);
   return EVENT_DONE;
 }
 
 
 static int
-remove_round_robin(HostDBInfo * r, char *hostname, unsigned int ip)
+remove_round_robin(HostDBInfo * r, char *hostname, sockaddr const* ip)
 {
   if (r) {
     if (!r->round_robin)
@@ -1012,10 +1054,12 @@ remove_round_robin(HostDBInfo * r, char 
     if (!rr)
       return false;
     for (int i = 0; i < rr->good; i++) {
-      if (rr->info[i].ip() == ip) {
-        Debug("hostdb", "Deleting %u.%u.%u.%u from '%s' round robin DNS entry",
-              ((unsigned char *) &ip)[0], ((unsigned char *) &ip)[1],
-              ((unsigned char *) &ip)[2], ((unsigned char *) &ip)[3], hostname);
+      if (0 == ink_inet_cmp(rr->info[i].ip(), ip)) {
+        ip_text_buffer b;
+        Debug("hostdb", "Deleting %s from '%s' round robin DNS entry",
+          ink_inet_ntop(ip, b, sizeof b),
+          hostname
+        );
         HostDBInfo tmp = rr->info[i];
         rr->info[i] = rr->info[rr->good - 1];
         rr->info[rr->good - 1] = tmp;
@@ -1025,13 +1069,12 @@ remove_round_robin(HostDBInfo * r, char 
           return false;
         } else {
           if (diags->on("hostdb")) {
-            int bufsize = (HOST_DB_MAX_ROUND_ROBIN_INFO * 16) * 2;
+            int bufsize = rr->good * INET6_ADDRSTRLEN;
             char *rr_ip_list = (char *) alloca(bufsize);
             char *p = rr_ip_list;
-            for (int n = 0; n < rr->good; n++) {
-              unsigned int rr_ip = rr->info[n].ip();
-              unsigned char *pip = (unsigned char *) &rr_ip;
-              int nbytes = snprintf(p, bufsize, "%hhu.%hhu.%hhu.%hhu ", pip[0], pip[1], pip[2], pip[3]);
+            for (int n = 0; n < rr->good; ++n) {
+              ink_inet_ntop(rr->info[n].ip(), p, bufsize);
+              int nbytes = strlen(p);
               p += nbytes;
               bufsize -= nbytes;
             }
@@ -1047,11 +1090,12 @@ remove_round_robin(HostDBInfo * r, char 
 
 
 Action *
-HostDBProcessor::failed_connect_on_ip_for_name(Continuation * cont, unsigned int ip, char *hostname, int len, int port)
+HostDBProcessor::failed_connect_on_ip_for_name(Continuation * cont, sockaddr const* ip, char *hostname, int len)
 {
   INK_MD5 md5;
   char *pServerLine = 0;
   void *pDS = 0;
+  unsigned short port = ink_inet_port_cast(ip);
 
 #ifdef SPLIT_DNS
   SplitDNS *pSD = 0;
@@ -1077,17 +1121,17 @@ HostDBProcessor::failed_connect_on_ip_fo
       return ACTION_RESULT_DONE;
     }
 #ifdef SPLIT_DNS
-    HostDBInfo *r = probe(mutex, md5, hostname, len, ip, port, pDS);
+    HostDBInfo *r = probe(mutex, md5, hostname, len, ip, pDS);
 #else
-    HostDBInfo *r = probe(mutex, md5, hostname, len, ip, port, 0);
+    HostDBInfo *r = probe(mutex, md5, hostname, len, ip, 0);
 #endif
     bool res = (remove_round_robin(r, hostname, ip) ? true : false);
     if (cont)
-      cont->handleEvent(EVENT_HOST_DB_IP_REMOVED, res ? (void *) &ip : (void *) NULL);
+      cont->handleEvent(EVENT_HOST_DB_IP_REMOVED, res ? (void *) ip : (void *) NULL);
     return ACTION_RESULT_DONE;
   }
   HostDBContinuation *c = hostDBContAllocator.alloc();
-  c->init(hostname, len, ip, port, md5, cont, pDS);
+  c->init(hostname, len, ip, md5, cont, pDS);
   SET_CONTINUATION_HANDLER(c, (HostDBContHandler) & HostDBContinuation::removeEvent);
   thread->schedule_in(c, MUTEX_RETRY_DELAY);
   return &c->action;
@@ -1110,10 +1154,13 @@ HostDBContinuation::removeEvent(int even
       if (cont)
         cont->handleEvent(EVENT_HOST_DB_IP_REMOVED, (void *) NULL);
     } else {
-      HostDBInfo *r = probe(mutex, md5, name, namelen, ip, port, m_pDS);
-      bool res = (remove_round_robin(r, name, ip) ? true : false);
+      HostDBInfo *r = probe(mutex, md5, name, namelen, &ip.sa, m_pDS);
+      bool res = (remove_round_robin(r, name, &ip.sa) ? true : false);
       if (cont)
-        cont->handleEvent(EVENT_HOST_DB_IP_REMOVED, res ? (void *) &ip : (void *) NULL);
+        cont->handleEvent(
+          EVENT_HOST_DB_IP_REMOVED,
+          res ? static_cast<void *>(&ip) : static_cast<void *>(NULL)
+        );
     }
   }
   hostdb_cont_free(this);
@@ -1125,20 +1172,19 @@ HostDBContinuation::removeEvent(int even
 // calling continuation or to the calling cluster node.
 //
 HostDBInfo *
-HostDBContinuation::lookup_done(int aip, char *aname, bool around_robin, unsigned int ttl_seconds, SRVHosts * srv)
+HostDBContinuation::lookup_done(sockaddr const* aip, char *aname, bool around_robin, unsigned int ttl_seconds, SRVHosts * srv)
 {
   HostDBInfo *i = NULL;
 
   ink_debug_assert(this_ethread() == hostDB.lock_for_bucket((int) (fold_md5(md5) % hostDB.buckets))->thread_holding);
-  if (!aip || !aname || !aname[0]) {
+  if (!aip || !ink_inet_is_ip(aip) || !aname || !aname[0]) {
     if (is_byname()) {
       Debug("hostdb", "lookup_done() failed for '%s'", name);
     } else if (is_srv()) {
       Debug("dns_srv", "SRV failed for '%s'", name);
     } else {
-      Debug("hostdb", "failed for %u.%u.%u.%u",
-            ((unsigned char *) &ip)[0], ((unsigned char *) &ip)[1],
-            ((unsigned char *) &ip)[2], ((unsigned char *) &ip)[3]);
+      ip_text_buffer b;
+      Debug("hostdb", "failed for %s", ink_inet_ntop(&ip.sa, b, sizeof b));
     }
     i = insert(hostdb_ip_fail_timeout_interval);        // currently ... 0
     i->round_robin = false;
@@ -1166,10 +1212,9 @@ HostDBContinuation::lookup_done(int aip,
       ttl_seconds = 1;          // www.barnsandnobel.com is lame
     i = insert(ttl_seconds);
     if (is_byname()) {
-      Debug("hostdb", "done %u.%u.%u.%u TTL %d",
-            ((unsigned char *) &aip)[0], ((unsigned char *) &aip)[1],
-            ((unsigned char *) &aip)[2], ((unsigned char *) &aip)[3], ttl_seconds);
-      i->ip() = aip;
+      ip_text_buffer b;
+      Debug("hostdb", "done %s TTL %d", ink_inet_ntop(aip, b, sizeof b), ttl_seconds);
+      ink_inet_copy(i->ip(), aip);
       i->round_robin = around_robin;
       i->reverse_dns = false;
       if (name != aname) {
@@ -1178,7 +1223,7 @@ HostDBContinuation::lookup_done(int aip,
       i->is_srv = false;
     } else if (is_srv()) {
 
-      i->ip() = aip;            /* this doesnt matter w. srv records -- setting to 1 so Md5 works */
+      ink_inet_copy(i->ip(), aip);  /* this doesnt matter w. srv records -- setting to 1 so Md5 works */
 
       i->reverse_dns = false;
 
@@ -1257,12 +1302,12 @@ restore_info(HostDBInfo * r, HostDBInfo 
 {
   if (old_rr_data) {
     for (int j = 0; j < old_rr_data->n; j++)
-      if (old_rr_data->info[j].ip() == r->ip()) {
+      if (ink_inet_eq(old_rr_data->info[j].ip(), r->ip())) {
         r->app = old_rr_data->info[j].app;
         return true;
       }
   } else if (old_r)
-    if (old_info.ip() == r->ip()) {
+    if (ink_inet_eq(old_info.ip(), r->ip())) {
       r->app = old_info.app;
       return true;
     }
@@ -1313,46 +1358,61 @@ HostDBContinuation::dnsEvent(int event, 
     ttl = failed ? 0 : e->ttl / 60;
     int ttl_seconds = failed ? 0 : e->ttl;      //ebalsa: moving to second accuracy
 
-    HostDBInfo *old_r = probe(mutex, md5, name, namelen, ip, port, m_pDS, true);
+    HostDBInfo *old_r = probe(mutex, md5, name, namelen, &ip.sa, m_pDS, true);
     HostDBInfo old_info;
     if (old_r)
       old_info = *old_r;
     HostDBRoundRobin *old_rr_data = old_r ? old_r->rr() : NULL;
 
-    int n = 0, nn = 0, first = -1;
+    int n = 0, nn = 0;
+    void* first = 0;
+    uint8_t af = e ? e->ent.h_addrtype : AF_UNSPEC;
     if (rr) {
+      af = e->ent.h_addrtype;
       if (is_srv() && !failed) {
         n = e->srv_hosts.getCount();
       } else {
-        for (; nn < HOST_DB_MAX_ROUND_ROBIN_INFO && e->ent.h_addr_list[nn]; nn++)
-          if (*(unsigned int *) e->ent.h_addr_list[nn]) {
-            if (first < 0)
-              first = nn;
-            n++;
-          } else
-            Warning("0.0.0.0 removed from round-robin list for '%s'", name);
-        if (first < 0) {
+        void* ptr; // tmp for current entry.
+        for (
+            ; nn < HOST_DB_MAX_ROUND_ROBIN_INFO
+              && 0 != (ptr = e->ent.h_addr_list[nn])
+            ; ++nn
+        ) {
+          if (is_addr_valid(af, ptr)) {
+            if (! first) first = ptr;
+            ++n;
+          } else {
+            Warning("Zero address removed from round-robin list for '%s'", name);
+          }
+          // what's the point of @a n? Should there be something like
+          // if (n != nn) e->ent.h_addr_list[n] = e->ent->h_addr_list[nn];
+          // with a final copy of the terminating null? - AMC
+        }
+        if (!first) {
           failed = true;
           rr = false;
         }
       }
-    } else {
-      first = 0;
-    }
+    } else if (!failed) {
+      first = e->ent.h_addr_list[0];
+    } // else first is 0.
 
     HostDBInfo *r = NULL;
+    sockaddr_storage tip; // temporary IP data.
+    sockaddr* tip_ptr = ink_inet_sa_cast(&tip);
+    ink_inet_invalidate(tip_ptr);
+    if (first) ip_addr_set(tip_ptr, af, first);
+
     if (is_byname())
-      r =
-        lookup_done(failed ? 0 : *(unsigned int *) e->ent.h_addr_list[first], name, rr, ttl_seconds,
-                    failed ? 0 : &e->srv_hosts);
+      r = lookup_done(tip_ptr, name, rr, ttl_seconds, failed ? 0 : &e->srv_hosts);
     else if (is_srv())
-      r = lookup_done(1,        /* junk: FIXME: is the code in lookup_done() wrong to NEED this? */
+      r = lookup_done(tip_ptr,  /* junk: FIXME: is the code in lookup_done() wrong to NEED this? */
                       name,     /* hostname */
                       rr,       /* is round robin, doesnt matter for SRV since we recheck getCount() inside lookup_done() */
                       ttl_seconds,      /* ttl in seconds */
                       failed ? 0 : &e->srv_hosts);
     else
-      r = lookup_done(failed ? 0 : ip, failed ? name : e->ent.h_name, false, ttl_seconds, failed ? 0 : &e->srv_hosts);
+      r = lookup_done(tip_ptr, failed ? name : e->ent.h_name, false, ttl_seconds, failed ? 0 : &e->srv_hosts);
 
     if (rr) {
       int s = HostDBRoundRobin::size(n, is_srv());
@@ -1363,45 +1423,47 @@ HostDBContinuation::dnsEvent(int event, 
         if (is_srv()) {
           SortableQueue<SRV> *q = e->srv_hosts.getHosts();
           if (q) {
-            for (i = 0; i < n; i++) {
-
+            for (i = 0; i < n; ++i) {
               SRV *t = q->dequeue();
+              HostDBInfo& item = rr_data->info[i];
 
-              rr_data->info[i].ip() = 1;
-              rr_data->info[i].round_robin = 0;
-              rr_data->info[i].reverse_dns = 0;
-
-              rr_data->info[i].srv_weight = t->getWeight();
-              rr_data->info[i].srv_priority = t->getPriority();
-              rr_data->info[i].srv_port = t->getPort();
+              ink_inet_invalidate(item.ip());
+              item.round_robin = 0;
+              item.reverse_dns = 0;
+
+              item.srv_weight = t->getWeight();
+              item.srv_priority = t->getPriority();
+              item.srv_port = t->getPort();
 
               ink_strncpy(rr_data->rr_srv_hosts[i], t->getHost(), MAXDNAME);
               rr_data->rr_srv_hosts[i][MAXDNAME - 1] = '\0';
-              rr_data->info[i].is_srv = true;
+              item.is_srv = true;
 
-              rr_data->info[i].full = 1;
-              rr_data->info[i].md5_high = r->md5_high;
-              rr_data->info[i].md5_low = r->md5_low;
-              rr_data->info[i].md5_low_low = r->md5_low_low;
+              item.full = 1;
+              item.md5_high = r->md5_high;
+              item.md5_low = r->md5_low;
+              item.md5_low_low = r->md5_low_low;
               SRVAllocator.free(t);
               Debug("dns_srv", "inserted SRV RR record into HostDB with TTL: %d seconds", ttl_seconds);
             }
           }
         } else {
-          for (; ii < nn; ii++) {
-            if (*(unsigned int *) e->ent.h_addr_list[ii]) {
-              rr_data->info[i].ip() = *(unsigned int *) e->ent.h_addr_list[ii];
-              rr_data->info[i].full = 1;
-              rr_data->info[i].round_robin = 0;
-              rr_data->info[i].reverse_dns = 0;
-              rr_data->info[i].md5_high = r->md5_high;
-              rr_data->info[i].md5_low = r->md5_low;
-              rr_data->info[i].md5_low_low = r->md5_low_low;
-              if (!restore_info(&rr_data->info[i], old_r, old_info, old_rr_data)) {
-                rr_data->info[i].app.allotment.application1 = 0;
-                rr_data->info[i].app.allotment.application2 = 0;
+          for (; ii < nn; ++ii) {
+            if (is_addr_valid(af, e->ent.h_addr_list[ii])) {
+              HostDBInfo& item = rr_data->info[i];
+              ip_addr_set(item.ip(), af, e->ent.h_addr_list[ii]);
+//              rr_data->info[i].ip() = *(unsigned int *) e->ent.h_addr_list[ii];
+              item.full = 1;
+              item.round_robin = 0;
+              item.reverse_dns = 0;
+              item.md5_high = r->md5_high;
+              item.md5_low = r->md5_low;
+              item.md5_low_low = r->md5_low_low;
+              if (!restore_info(&item, old_r, old_info, old_rr_data)) {
+                item.app.allotment.application1 = 0;
+                item.app.allotment.application2 = 0;
               }
-              i++;
+              ++i;
             }
           }
         }
@@ -1455,11 +1517,9 @@ HostDBContinuation::dnsEvent(int event, 
 // HostDB Get Message
 // Used to lookup host information on a remote node in the cluster
 //
-struct HostDB_get_message
-{
+struct HostDB_get_message {
   INK_MD5 md5;
-  unsigned int ip;
-  int port;
+  ts_ip_endpoint ip;
   Continuation *cont;
   int namelen;
   char name[MAXDNAME];
@@ -1474,10 +1534,9 @@ HostDBContinuation::make_get_message(cha
 {
   ink_assert(size >= (int) sizeof(HostDB_get_message));
 
-  HostDB_get_message *msg = (HostDB_get_message *) buf;
+  HostDB_get_message *msg = reinterpret_cast<HostDB_get_message *>(buf);
   msg->md5 = md5;
-  msg->port = htonl(port);
-  msg->ip = htonl(ip);
+  ink_inet_copy(&msg->ip.sa, &ip.sa);
   msg->cont = this;
 
   // name
@@ -1543,32 +1602,17 @@ bool HostDBContinuation::do_get_response
 // This message is used in a response to a cluster node for
 // Host inforamation.
 //
-struct HostDB_put_message
-{
-  INK_MD5
-    md5;
-  unsigned int
-    ip;
-  unsigned int
-    ttl;
-  int
-    port;
-  unsigned int
-    missing:
-    1;
-  unsigned int
-    round_robin:
-    1;
-  Continuation *
-    cont;
-  unsigned int
-    application1;
-  unsigned int
-    application2;
-  int
-    namelen;
-  char
-    name[MAXDNAME];
+struct HostDB_put_message {
+  INK_MD5 md5;
+  ts_ip_endpoint ip;
+  unsigned int ttl;
+  unsigned int missing:1;
+  unsigned int round_robin:1;
+  Continuation* cont;
+  unsigned int application1;
+  unsigned int application2;
+  int namelen;
+  char name[MAXDNAME];
 };
 
 
@@ -1580,13 +1624,13 @@ HostDBContinuation::make_put_message(Hos
 {
   ink_assert(size >= (int) sizeof(HostDB_put_message));
 
-  HostDB_put_message *msg = (HostDB_put_message *) buf;
+  HostDB_put_message *msg = reinterpret_cast<HostDB_put_message *>(buf);
   memset(msg, 0, sizeof(HostDB_put_message));
 
   msg->md5 = md5;
   msg->cont = c;
   if (r) {
-    msg->ip = htonl(r->ip());
+    ink_inet_copy(&msg->ip.sa, r->ip());
     msg->application1 = r->app.allotment.application1;
     msg->application2 = r->app.allotment.application2;
     msg->missing = false;
@@ -1598,7 +1642,6 @@ HostDBContinuation::make_put_message(Hos
 
   // name
   ink_strncpy(msg->name, name, sizeof(msg->name));
-  msg->port = port;
 
   // length
   int len = sizeof(HostDB_put_message) - MAXDNAME + strlen(name) + 1;
@@ -1648,7 +1691,7 @@ HostDBContinuation::probeEvent(int event
     return EVENT_DONE;
   }
 
-  if (!hostdb_enable || (!*name && !ip)) {
+  if (!hostdb_enable || (!*name && !ink_inet_is_ip(&ip.sa))) {
     if (action.continuation)
       action.continuation->handleEvent(EVENT_HOST_DB_LOOKUP, NULL);
 #ifdef NON_MODULAR
@@ -1663,7 +1706,7 @@ HostDBContinuation::probeEvent(int event
 
     // Do the probe
     //
-    HostDBInfo *r = probe(mutex, md5, name, namelen, ip, port, m_pDS);
+    HostDBInfo *r = probe(mutex, md5, name, namelen, &ip.sa, m_pDS);
 
     if (r)
       HOSTDB_INCREMENT_DYN_STAT(hostdb_total_hits_stat);
@@ -1745,11 +1788,11 @@ HostDBContinuation::do_dns()
   ink_assert(!action.cancelled);
   if (is_byname()) {
     Debug("hostdb", "DNS %s", name);
-    unsigned int tip = ink_inet_addr(name);
-    // check 127.0.0.1 format
-    if ((int) tip != -1) {
+    ts_ip_endpoint tip;
+    if (0 == ink_inet_pton(name, &tip.sa)) {
+      // check 127.0.0.1 format // What the heck does that mean? - AMC
       if (action.continuation) {
-        HostDBInfo *r = lookup_done(tip, name, false, HOST_DB_MAX_TTL, NULL);
+        HostDBInfo *r = lookup_done(&tip.sa, name, false, HOST_DB_MAX_TTL, NULL);
         reply_to_cont(action.continuation, r);
       }
       hostdb_cont_free(this);
@@ -1766,7 +1809,7 @@ HostDBContinuation::do_dns()
       DNSHandler *dnsH = 0;
 #ifdef SPLIT_DNS
       if (m_pDS)
-        dnsH = (DNSHandler *) (((DNSServer *) (m_pDS))->x_dnsH);
+        dnsH = static_cast<DNSServer *>(m_pDS)->x_dnsH;
 #endif
       pending_action = dnsProcessor.gethostbyname(this, name, dnsH, dns_lookup_timeout);
     } else if (is_srv()) {
@@ -1774,10 +1817,9 @@ HostDBContinuation::do_dns()
       Debug("dns_srv", "SRV lookup of %s", name);
       pending_action = dnsProcessor.getSRVbyname(this, name, dnsH, dns_lookup_timeout);
     } else {
-      Debug("hostdb", "DNS IP %u.%u.%u.%u",
-            ((unsigned char *) &ip)[0], ((unsigned char *) &ip)[1],
-            ((unsigned char *) &ip)[2], ((unsigned char *) &ip)[3]);
-      pending_action = dnsProcessor.gethostbyaddr(this, ip, dns_lookup_timeout);
+      ip_text_buffer ipb;
+      Debug("hostdb", "DNS IP %s", ink_inet_ntop(&ip.sa, ipb, sizeof ipb));
+      pending_action = dnsProcessor.gethostbyaddr(this, &ip.sa, dns_lookup_timeout);
     }
   } else {
     SET_HANDLER((HostDBContHandler) & HostDBContinuation::dnsPendingEvent);
@@ -1818,7 +1860,7 @@ HostDBContinuation::clusterResponseEvent
     action = 0;
     // just a remote fill
     ink_assert(!missing);
-    lookup_done(ip, name, false, ttl, NULL);
+    lookup_done(&ip.sa, name, false, ttl, NULL);
   }
   hostdb_cont_free(this);
   return EVENT_DONE;
@@ -1850,7 +1892,7 @@ HostDBContinuation::clusterEvent(int eve
     }
     if (e) {
       HostDBContinuation *c = (HostDBContinuation *) e;
-      HostDBInfo *r = lookup_done(c->ip, c->name, false, c->ttl, NULL);
+      HostDBInfo *r = lookup_done(&c->ip.sa, c->name, false, c->ttl, NULL);
       r->app.allotment.application1 = c->app.allotment.application1;
       r->app.allotment.application2 = c->app.allotment.application2;
 
@@ -1939,8 +1981,7 @@ get_hostinfo_ClusterFunction(ClusterMach
      ----------------------------------------- */
 
 
-  c->init(msg->name, msg->namelen, ntohl(msg->ip), ntohl(msg->port), msg->md5, NULL, pDS);
-  TEST(printf("get_hostinfo_ClusterFunction %s %d\n", msg->name, msg->ip));
+  c->init(msg->name, msg->namelen, &msg->ip.sa, msg->md5, NULL, pDS);
   c->mutex = hostDB.lock_for_bucket(fold_md5(msg->md5) % hostDB.buckets);
   c->action.mutex = c->mutex;
   dnsProcessor.thread->schedule_imm(c);
@@ -1955,8 +1996,7 @@ put_hostinfo_ClusterFunction(ClusterMach
   HostDBContinuation *c = hostDBContAllocator.alloc();
 
   SET_CONTINUATION_HANDLER(c, (HostDBContHandler) & HostDBContinuation::clusterResponseEvent);
-  c->init(msg->name, msg->namelen, ntohl(msg->ip), ntohl(msg->port), msg->md5, NULL);
-  TEST(printf("put_hostinfo_ClusterFunction %s %d\n", msg->name, msg->ip));
+  c->init(msg->name, msg->namelen, &msg->ip.sa, msg->md5, NULL);
   c->mutex = hostDB.lock_for_bucket(fold_md5(msg->md5) % hostDB.buckets);
   c->from_cont = msg->cont;     // cannot use action if cont freed due to timeout
   c->missing = msg->missing;
@@ -2081,7 +2121,7 @@ typedef int (ShowHostDB::*ShowHostDBEven
 struct ShowHostDB: public ShowCont
 {
   char *name;
-  unsigned int ip;
+  ts_ip_endpoint ip;
   bool force;
 
   int showMain(int event, Event * e)
@@ -2110,13 +2150,14 @@ struct ShowHostDB: public ShowCont
     if (name)
       hostDBProcessor.getbyname_re(this, name, 0, force ? HostDBProcessor::HOSTDB_FORCE_DNS_ALWAYS : 0);
     else
-      hostDBProcessor.getbyaddr_re(this, ip);
+      hostDBProcessor.getbyaddr_re(this, &ip.sa);
     return EVENT_CONT;
   }
 
 
   int showOne(HostDBInfo * r, bool rr, int event, Event * e)
   {
+    ip_text_buffer b;
     CHECK_SHOW(show("<table border=1>\n"));
     CHECK_SHOW(show("<tr><td>%s</td><td>%s%s</td></tr>\n",
                     "Type", r->round_robin ? "Round-Robin" : "", r->reverse_dns ? "Reverse DNS" : "DNS"));
@@ -2130,7 +2171,7 @@ struct ShowHostDB: public ShowCont
     if (r->reverse_dns) {
       CHECK_SHOW(show("<tr><td>%s</td><td>%s</td></tr>\n", "Hostname", r->hostname()? r->hostname() : "<none>"));
     } else {
-      CHECK_SHOW(show("<tr><td>%s</td><td>%u.%u.%u.%u</td></tr>\n", "IP", PRINT_IP(r->ip())));
+      CHECK_SHOW(show("<tr><td>%s</td><td>%s</td></tr>\n", "IP", ink_inet_ntop(r->ip(), b, sizeof b)));
     }
     CHECK_SHOW(show("</table>\n"));
     return EVENT_CONT;
@@ -2164,7 +2205,8 @@ struct ShowHostDB: public ShowCont
       }
     } else {
       if (name) {
-        CHECK_SHOW(show("<H2>%u.%u.%u.%u Not Found</H2>\n", PRINT_IP(ip)));
+        ip_text_buffer b;
+        CHECK_SHOW(show("<H2>%s Not Found</H2>\n", ink_inet_ntop(&ip.sa, b, sizeof b)));
       } else {
         CHECK_SHOW(show("<H2>%s Not Found</H2>\n", name));
       }
@@ -2173,10 +2215,13 @@ struct ShowHostDB: public ShowCont
   }
 
 
-ShowHostDB(Continuation * c, HTTPHdr * h):
-  ShowCont(c, h), name(0), ip(0), force(0) {
-    SET_HANDLER(&ShowHostDB::showMain);
-  }
+  ShowHostDB(Continuation * c, HTTPHdr * h)
+    : ShowCont(c, h), name(0), force(0)
+    {
+      ink_inet_invalidate(&ip);
+      SET_HANDLER(&ShowHostDB::showMain);
+    }
+
 };
 
 #define STR_LEN_EQ_PREFIX(_x,_l,_s) (!ptr_len_ncasecmp(_x,_l,_s,sizeof(_s)-1))
@@ -2198,8 +2243,9 @@ register_ShowHostDB(Continuation * c, HT
     char *gn = NULL;
     if (s->sarg)
       gn = (char *)memchr(s->sarg, '=', strlen(s->sarg));
-    if (gn)
-      s->ip = ink_inet_addr(gn + 1);
+    if (gn) {
+      ink_inet_pton(gn+1, &s->ip); // hope that's null terminated.
+    }
     SET_CONTINUATION_HANDLER(s, &ShowHostDB::showLookup);
   } else if (STR_LEN_EQ_PREFIX(path, path_len, "name")) {
     s->force = !ptr_len_ncasecmp(path + 5, path_len - 5, "force", 5);
@@ -2248,12 +2294,13 @@ struct HostDBTestReverse: public Continu
 #else
       l = lrand48();
 #endif
-      unsigned int ip = (unsigned int) l;
+      ts_ip_endpoint ip;
+      ip.sin.sin_addr.s_addr = static_cast<in_addr_t>(l);
       outstanding++;
       total++;
       if (!(outstanding % 1000))
         printf("HostDBTestReverse: %d\n", total);
-      hostDBProcessor.getbyaddr_re(this, ip);
+      hostDBProcessor.getbyaddr_re(this, &ip.sa);
     }
     if (!outstanding) {
       printf("HostDBTestReverse: done\n");

Modified: trafficserver/traffic/trunk/iocore/hostdb/I_HostDBProcessor.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/hostdb/I_HostDBProcessor.h?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/hostdb/I_HostDBProcessor.h (original)
+++ trafficserver/traffic/trunk/iocore/hostdb/I_HostDBProcessor.h Wed Aug 10 23:22:53 2011
@@ -119,21 +119,18 @@ struct HostDBRoundRobin;
 
 struct HostDBInfo
 {
-  // Public Interface
-  unsigned int &ip()  {
-    return data.ip;
-  }
+  /** Internal IP address data.
+      This is at least large enough to hold an IPv6 address.
+  */
+  sockaddr* ip()  { return &data.ip.sa; }
+  sockaddr const* ip() const { return &data.ip.sa; }
 
   char *hostname();
   char *srvname();
   HostDBRoundRobin *rr();
 
   /** Indicate that the HostDBInfo is BAD and should be deleted. */
-  void bad()
-  {
-    full = 0;
-  }
-
+  void bad() { full = 0; }
 
   /** Check the HostDBInfo or selected RR entry of a HostDBInfo is ok. */
   int ok(bool byname, HostDBInfo * rr = NULL) {
@@ -145,7 +142,7 @@ struct HostDBInfo
     } else if (byname) {
       if (reverse_dns)
         goto Lbad;
-      if (!ip())
+      if (!ink_inet_is_ip(ip()))
         goto Lbad;
     } else {
       if (!reverse_dns)
@@ -220,27 +217,25 @@ struct HostDBInfo
     database. Any new user fields must be added to this function.
 
   */
-  void set_from(HostDBInfo & info)
+  void set_from(HostDBInfo const& that)
   {
-    ip() = info.ip();
-    ip_timestamp = info.ip_timestamp;
-    ip_timeout_interval = info.ip_timeout_interval;
-    round_robin = info.round_robin;
-    reverse_dns = info.reverse_dns;
-    app.allotment.application1 = info.app.allotment.application1;
-    app.allotment.application2 = info.app.allotment.application2;
+    memcpy(&data, &that.data, sizeof data);
+    ip_timestamp = that.ip_timestamp;
+    ip_timeout_interval = that.ip_timeout_interval;
+    round_robin = that.round_robin;
+    reverse_dns = that.reverse_dns;
+    app.allotment.application1 = that.app.allotment.application1;
+    app.allotment.application2 = that.app.allotment.application2;
   }
 
 
   //
   // Private
   //
-  union
-  {
-    unsigned int ip;
-    int hostname_offset;
-    // int srv_host_offset;
-    uint64_t dummy_pad;
+
+  union {
+    ts_ip_endpoint ip; ///< IP address / port data.
+    int hostname_offset; ///< Some hostname thing.
   } data;
 
   unsigned int srv_weight:16;
@@ -266,10 +261,8 @@ struct HostDBInfo
 
   uint64_t md5_high;
 
-  sockaddr_in6 ip_addr; // used only by API as storage.
-
-  bool failed() { return !ip(); }
-  void set_failed() { ip() = 0;  }
+  bool failed() { return !ink_inet_is_ip(ip()); }
+  void set_failed() { ink_inet_invalidate(ip());  }
 
   void set_deleted() { deleted = 1; }
   bool is_deleted() const { return deleted; }
@@ -302,7 +295,7 @@ struct HostDBInfo
 
   void reset()
   {
-    ip() = 0;
+    ink_inet_invalidate(ip());
     app.allotment.application1 = 0;
     app.allotment.application2 = 0;
     backed = 0;
@@ -322,17 +315,28 @@ struct HostDBInfo
   int *heap_offset_ptr();
 
 HostDBInfo()
-  : srv_weight(0), srv_priority(0), srv_port(0), srv_count(0), is_srv(0),
-    ip_timestamp(0),
-    ip_timeout_interval(0), full(0), backed(0), deleted(0), hits(0), round_robin(0), reverse_dns(0), md5_low_low(0),
-    md5_low(0), md5_high(0) {
+  : srv_weight(0)
+  , srv_priority(0)
+  , srv_port(0)
+  , srv_count(0)
+  , is_srv(0)
+  , ip_timestamp(0)
+  , ip_timeout_interval(0)
+  , full(0)
+  , backed(0)
+  , deleted(0)
+  , hits(0)
+  , round_robin(0)
+  , reverse_dns(0)
+  , md5_low_low(0)
+  , md5_low(0), md5_high(0) {
 #ifdef PURIFY
     memset(&app, 0, sizeof(app));
 #else
     app.allotment.application1 = 0;
     app.allotment.application2 = 0;
 #endif
-    ip() = 0;
+    ink_inet_invalidate(ip());
 
     return;
   }
@@ -371,10 +375,22 @@ struct HostDBRoundRobin
     }
   }
 
-  HostDBInfo *find_ip(unsigned int ip);
-  HostDBInfo *select_best(unsigned int client_ip, HostDBInfo * r = NULL);
+  HostDBInfo *find_ip(sockaddr const* addr);
+  HostDBInfo *select_best(sockaddr const* client_ip, HostDBInfo * r = NULL);
+
+  HostDBInfo *select_best_http(sockaddr const* client_ip, time_t now, int32_t fail_window);
+
+  HostDBInfo *select_best(in_addr_t client_ip, HostDBInfo * r = NULL) {
+    sockaddr_in ip4;
+    ink_inet_ip4_set(&ip4, client_ip);
+    return this->select_best(ink_inet_sa_cast(&ip4), r);
+  }
 
-  HostDBInfo *select_best_http(unsigned int client_ip, time_t now, int32_t fail_window);
+  HostDBInfo *select_best_http(in_addr_t client_ip, time_t now, int32_t fail_window) {
+    sockaddr_in ip4;
+    ink_inet_ip4_set(&ip4, client_ip);
+    return this->select_best_http(ink_inet_sa_cast(&ip4), now, fail_window);
+  }
 
   HostDBInfo *increment_round_robin()
   {
@@ -432,12 +448,19 @@ struct HostDBProcessor: public Processor
   Action *getSRVbyname_imm(Continuation * cont, process_srv_info_pfn process_srv_info, char *hostname, int len = 0,
                            int port = 0, int flags = HOSTDB_DO_NOT_FORCE_DNS, int timeout = 0);
 
-  Action *getbyname_imm(Continuation * cont, process_hostdb_info_pfn process_hostdb_info, char *hostname, int len = 0,
-                        int port = 0, int flags = HOSTDB_DO_NOT_FORCE_DNS, int timeout = 0);
+  Action *getbyname_imm(
+    Continuation * cont,
+    process_hostdb_info_pfn process_hostdb_info,
+    char *hostname,
+    int len = 0,
+    int port = 0,
+    int flags = HOSTDB_DO_NOT_FORCE_DNS,
+    int timeout = 0
+  );
 
 
   /** Lookup Hostinfo by addr */
-  Action *getbyaddr_re(Continuation * cont, unsigned int aip)
+  Action *getbyaddr_re(Continuation * cont, sockaddr const* aip)
   {
     return getby(cont, NULL, 0, 0, aip, false);
   }
@@ -450,18 +473,29 @@ struct HostDBProcessor: public Processor
     you will get a different IP address.
 
   */
-  Action *failed_connect_on_ip_for_name(Continuation * cont,
-                                        unsigned int aip, char *hostname, int len = 0, int port = 0);
+  Action *failed_connect_on_ip_for_name(
+    Continuation * cont,
+    sockaddr const* aip,
+    char *hostname, int len = 0
+  );
 
   /** Set the application information (fire-and-forget). */
   void setbyname_appinfo(char *hostname, int len, int port, HostDBApplicationInfo * app)
   {
-    setby(hostname, len, port, 0, app);
+    sockaddr_in addr;
+    ink_inet_ip4_set(&addr, INADDR_ANY, port);
+    setby(hostname, len, ink_inet_sa_cast(&addr), app);
+  }
+
+  void setbyaddr_appinfo(sockaddr const* addr, HostDBApplicationInfo * app) {
+    this->setby(0, 0, addr, app);
   }
 
-  void setbyaddr_appinfo(unsigned int ip, HostDBApplicationInfo * app)
+  void setbyaddr_appinfo(in_addr_t ip, HostDBApplicationInfo * app)
   {
-    setby(0, 0, 0, ip, app);
+    sockaddr_in addr;
+    ink_inet_ip4_set(&addr, ip);
+    this->setby(0, 0, ink_inet_sa_cast(&addr), app);
   }
 
   /** Configuration. */
@@ -475,9 +509,23 @@ struct HostDBProcessor: public Processor
 
   // Private
   HostDBCache *cache();
-  Action *getby(Continuation * cont, char *hostname, int len, int port,
-                unsigned int ip, bool aforce_dns, int timeout = 0);
-  void setby(char *hostname, int len, int port, unsigned int aip, HostDBApplicationInfo * app);
+  Action *getby(
+    Continuation * cont,
+    char *hostname, int len,
+    sockaddr const* ip,
+    bool aforce_dns, int timeout = 0
+  );
+  /** Set something.
+      @a aip can carry address and / or port information. If setting just
+      by a port value, the address should be set to INADDR_ANY which is of
+      type IPv4.
+   */
+  void setby(
+    char *hostname, ///< Hostname.
+    int len, ///< Length of hostname.
+    sockaddr const* aip, ///< Address and/or port.
+    HostDBApplicationInfo * app ///< I don't know.
+  );
 
 };
 

Modified: trafficserver/traffic/trunk/iocore/hostdb/P_HostDB.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/hostdb/P_HostDB.h?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/hostdb/P_HostDB.h (original)
+++ trafficserver/traffic/trunk/iocore/hostdb/P_HostDB.h Wed Aug 10 23:22:53 2011
@@ -60,7 +60,7 @@
                                     PRIVATE_MODULE_HEADER)
 HostDBInfo *probe(ProxyMutex * mutex,
                   INK_MD5 & md5, char *hostname, int len,
-                  int ip, int port, void *pDS, bool ignore_timeout = false, bool is_srv_lookup = false);
+                  sockaddr const* addr, void *pDS, bool ignore_timeout = false, bool is_srv_lookup = false);
 
 void make_md5(INK_MD5 & md5, char *hostname, int len, int port, char *pDNSServers = 0, int srv = 0);
 #endif

Modified: trafficserver/traffic/trunk/iocore/hostdb/P_HostDBProcessor.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/hostdb/P_HostDBProcessor.h?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/hostdb/P_HostDBProcessor.h (original)
+++ trafficserver/traffic/trunk/iocore/hostdb/P_HostDBProcessor.h Wed Aug 10 23:22:53 2011
@@ -30,8 +30,26 @@
 
 #include "I_HostDBProcessor.h"
 
-
-#define HOSTDB_CLIENT_IP_HASH(_client_ip,_ip) (((_client_ip >> 16)^_client_ip^_ip^(_ip>>16))&0xFFFF)
+inline unsigned int HOSTDB_CLIENT_IP_HASH(
+  sockaddr const* lhs,
+  sockaddr const* rhs
+) {
+  unsigned int zret = ~static_cast<unsigned int>(0);
+  if (ink_inet_are_compatible(lhs,rhs)) {
+    if (ink_inet_is_ip4(lhs)) {
+      in_addr_t ip1 = ink_inet_ip4_addr_cast(lhs);
+      in_addr_t ip2 = ink_inet_ip4_addr_cast(rhs);
+      zret = (ip1 >> 16) ^ ip1 ^ ip2 ^ (ip2 >> 16);
+    } else if (ink_inet_is_ip6(lhs)) {
+      uint32_t const* ip1 = ink_inet_ip_addr32_cast(lhs);
+      uint32_t const* ip2 = ink_inet_ip_addr32_cast(rhs);
+      for ( int i = 0 ; i < 4 ; ++i, ++ip1, ++ip2 ) {
+        zret ^= (*ip1 >> 16) ^ *ip1 ^ *ip2 ^ (*ip2 >> 16);
+      }
+    }
+  }
+  return zret & 0xFFFF;
+}
 
 //
 // Constants
@@ -44,7 +62,8 @@
 
 // Bump this any time hostdb format is changed
 #define HOST_DB_CACHE_MAJOR_VERSION         2
-#define HOST_DB_CACHE_MINOR_VERSION         0
+#define HOST_DB_CACHE_MINOR_VERSION         1
+// 2.1 : IPv6
 
 #define DEFAULT_HOST_DB_FILENAME             "host.db"
 #define DEFAULT_HOST_DB_SIZE                 (1<<14)
@@ -146,9 +165,8 @@ struct HostDBCache: public MultiCache<Ho
   HostDBCache();
 };
 
-inline HostDBInfo *
-HostDBRoundRobin::find_ip(unsigned int ip)
-{
+inline HostDBInfo*
+HostDBRoundRobin::find_ip(sockaddr const* ip) {
   bool bad = (n <= 0 || n > HOST_DB_MAX_ROUND_ROBIN_INFO || good <= 0 || good > HOST_DB_MAX_ROUND_ROBIN_INFO);
   if (bad) {
     ink_assert(!"bad round robin size");
@@ -156,7 +174,7 @@ HostDBRoundRobin::find_ip(unsigned int i
   }
 
   for (int i = 0; i < good; i++) {
-    if (ip == info[i].ip()) {
+    if (ink_inet_eq(ip, info[i].ip())) {
       return &info[i];
     }
   }
@@ -165,7 +183,7 @@ HostDBRoundRobin::find_ip(unsigned int i
 }
 
 inline HostDBInfo *
-HostDBRoundRobin::select_best(unsigned int client_ip, HostDBInfo * r)
+HostDBRoundRobin::select_best(sockaddr const* client_ip, HostDBInfo * r)
 {
   (void) r;
   bool bad = (n <= 0 || n > HOST_DB_MAX_ROUND_ROBIN_INFO || good <= 0 || good > HOST_DB_MAX_ROUND_ROBIN_INFO);
@@ -177,7 +195,7 @@ HostDBRoundRobin::select_best(unsigned i
   if (HostDBProcessor::hostdb_strict_round_robin) {
     best = current++ % good;
   } else {
-    unsigned int ip = info[0].ip();
+    sockaddr const* ip = info[0].ip();
     unsigned int best_hash = HOSTDB_CLIENT_IP_HASH(client_ip, ip);
     for (int i = 1; i < good; i++) {
       ip = info[i].ip();
@@ -192,7 +210,7 @@ HostDBRoundRobin::select_best(unsigned i
 }
 
 inline HostDBInfo *
-HostDBRoundRobin::select_best_http(unsigned int client_ip, time_t now, int32_t fail_window)
+HostDBRoundRobin::select_best_http(sockaddr const* client_ip, time_t now, int32_t fail_window)
 {
   bool bad = (n <= 0 || n > HOST_DB_MAX_ROUND_ROBIN_INFO || good <= 0 || good > HOST_DB_MAX_ROUND_ROBIN_INFO);
   if (bad) {
@@ -208,7 +226,7 @@ HostDBRoundRobin::select_best_http(unsig
   } else {
     unsigned int best_hash_any = 0;
     unsigned int best_hash_up = 0;
-    unsigned int ip;
+    sockaddr const* ip;
     for (int i = 0; i < good; i++) {
       ip = info[i].ip();
       unsigned int h = HOSTDB_CLIENT_IP_HASH(client_ip, ip);
@@ -269,9 +287,8 @@ typedef int (HostDBContinuation::*HostDB
 struct HostDBContinuation: public Continuation
 {
   Action action;
-  unsigned int ip;
+  ts_ip_endpoint ip;
   unsigned int ttl;
-  int port;
   bool is_srv_lookup;
   int dns_lookup_timeout;
   INK_MD5 md5;
@@ -309,7 +326,7 @@ struct HostDBContinuation: public Contin
   {
     return ((*name && is_srv_lookup) ? true : false);
   }
-  HostDBInfo *lookup_done(int aip, char *aname, bool round_robin, unsigned int attl, SRVHosts * s = NULL);
+  HostDBInfo *lookup_done(sockaddr const* aip, char *aname, bool round_robin, unsigned int attl, SRVHosts * s = NULL);
   bool do_get_response(Event * e);
   void do_put_response(ClusterMachine * m, HostDBInfo * r, Continuation * cont);
   int failed_cluster_request(Event * e);
@@ -321,16 +338,17 @@ struct HostDBContinuation: public Contin
 
   HostDBInfo *insert(unsigned int attl);
 
-  void init(char *hostname, int len, int aip, int port, INK_MD5 & amd5,
+  void init(char *hostname, int len, sockaddr const* ip, INK_MD5 & amd5,
             Continuation * cont, void *pDS = 0, bool is_srv = false, int timeout = 0);
   int make_get_message(char *buf, int len);
   int make_put_message(HostDBInfo * r, Continuation * c, char *buf, int len);
 
 HostDBContinuation():
-  Continuation(NULL), ip(0), ttl(0), port(0),
+  Continuation(NULL), ttl(0),
     is_srv_lookup(false), dns_lookup_timeout(0),
     timeout(0), from(0),
     from_cont(0), probe_depth(0), namelen(0), missing(false), force_dns(false), round_robin(false) {
+    memset(&ip, 0, sizeof ip);
     memset(name, 0, MAXDNAME);
     md5.b[0] = 0;
     md5.b[1] = 0;

Modified: trafficserver/traffic/trunk/iocore/hostdb/P_MultiCache.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/hostdb/P_MultiCache.h?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/hostdb/P_MultiCache.h (original)
+++ trafficserver/traffic/trunk/iocore/hostdb/P_MultiCache.h Wed Aug 10 23:22:53 2011
@@ -59,7 +59,8 @@
 // Update these if there is a change to MultiCacheBase
 // There is a separate HOST_DB_CACHE_[MAJOR|MINOR]_VERSION
 #define MULTI_CACHE_MAJOR_VERSION    2
-#define MULTI_CACHE_MINOR_VERSION    0
+#define MULTI_CACHE_MINOR_VERSION    1
+// 2.1 - IPv6 compatible
 
 #define MULTI_CACHE_HEAP_HIGH_WATER  0.8
 

Modified: trafficserver/traffic/trunk/lib/ts/ink_inet.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_inet.h?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_inet.h (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_inet.h Wed Aug 10 23:22:53 2011
@@ -357,7 +357,8 @@ inline uint32_t const* ink_inet_ip_addr3
 
 /** Copy the address from @a src to @a dst if it's IP.
     This attempts to do a minimal copy based on the type of @a src.
-    If @a src is not an IP address type it is @b not copied.
+    If @a src is not an IP address type it is @b not copied and
+    @a dst is marked as invalid.
     @return @c true if @a src was an IP address, @c false otherwise.
 */
 inline bool ink_inet_copy(
@@ -365,9 +366,11 @@ inline bool ink_inet_copy(
   sockaddr const* src ///< Source object.
 ) {
   size_t n = 0;
-  switch (src->sa_family) {
-  case AF_INET: n = sizeof(sockaddr_in); break;
-  case AF_INET6: n = sizeof(sockaddr_in6); break;
+  if (src) {
+    switch (src->sa_family) {
+    case AF_INET: n = sizeof(sockaddr_in); break;
+    case AF_INET6: n = sizeof(sockaddr_in6); break;
+    }
   }
   if (n) memcpy(dst, src, n);
   else ink_inet_invalidate(dst);
@@ -470,6 +473,13 @@ inline int ink_inet_cmp(sockaddr_in6 con
 inline bool ink_inet_eq(sockaddr const* lhs, sockaddr const* rhs) {
   return 0 == ink_inet_cmp(lhs, rhs);
 }
+inline bool ink_inet_eq(ts_ip_endpoint const& lhs, ts_ip_endpoint const& rhs) {
+  return 0 == ink_inet_cmp(&lhs.sa, &rhs.sa);
+}
+
+inline bool operator == (ts_ip_endpoint const& lhs, ts_ip_endpoint const& rhs) {
+  return 0 == ink_inet_cmp(&lhs.sa, &rhs.sa);
+}
 
 //@}
 
@@ -494,7 +504,7 @@ inline in_addr_t ink_inet_get_ip4_addr(
 }
 
 /// Write IPv4 data to storage @a dst.
-inline void ink_inet_ip4_set(
+inline sockaddr* ink_inet_ip4_set(
   sockaddr_in* dst, ///< Destination storage.
   in_addr_t addr, ///< address, IPv4 network order.
   uint16_t port = 0 ///< port, network order.
@@ -503,17 +513,18 @@ inline void ink_inet_ip4_set(
   dst->sin_family = AF_INET;
   dst->sin_addr.s_addr = addr;
   dst->sin_port = port;
+  return ink_inet_sa_cast(dst);
 }
 
 /** Write IPv4 data to @a dst.
     @note Convenience overload.
 */
-inline void ink_inet_ip4_set(
+inline sockaddr* ink_inet_ip4_set(
   sockaddr_in6* dst, ///< Destination storage.
   in_addr_t ip4, ///< address, IPv4 network order.
   uint16_t port = 0 ///< port, network order.
 ) {
-  ink_inet_ip4_set(ink_inet_ip4_cast(dst), ip4, port);
+  return ink_inet_ip4_set(ink_inet_ip4_cast(dst), ip4, port);
 }
 
 /** Write IPv4 data to storage @a dst.
@@ -521,12 +532,12 @@ inline void ink_inet_ip4_set(
     This is the generic overload. Caller must verify that @a dst is at
     least @c sizeof(sockaddr_in) bytes.
 */
-inline void ink_inet_ip4_set(
+inline sockaddr* ink_inet_ip4_set(
   sockaddr* dst, ///< Destination storage.
   in_addr_t ip4, ///< address, IPv4 network order.
   uint16_t port = 0 ///< port, network order.
 ) {
-  ink_inet_ip4_set(ink_inet_ip4_cast(dst), ip4, port);
+  return ink_inet_ip4_set(ink_inet_ip4_cast(dst), ip4, port);
 }
 
 /// Write IPv6 address to storage @a dst.

Modified: trafficserver/traffic/trunk/proxy/InkAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/InkAPI.cc?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/InkAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/InkAPI.cc Wed Aug 10 23:22:53 2011
@@ -6233,15 +6233,14 @@ TSHostLookupResultAddrGet(TSHostLookupRe
 {
   sdk_assert(sdk_sanity_check_hostlookup_structure(lookup_result) == TS_SUCCESS);
   HostDBInfo* di = reinterpret_cast<HostDBInfo*>(lookup_result);
-  ink_inet_ip4_set(&di->ip_addr, di->ip());
-  return ink_inet_sa_cast(&di->ip_addr);
+  return di->ip();
 }
 
 in_addr_t
 TSHostLookupResultIpGet(TSHostLookupResult lookup_result)
 {
   sdk_assert(sdk_sanity_check_hostlookup_structure(lookup_result) == TS_SUCCESS);
-  return ((HostDBInfo *)lookup_result)->ip();
+  return ink_inet_ip4_addr_cast(((HostDBInfo *)lookup_result)->ip());
 }
 
 void
@@ -6252,7 +6251,7 @@ TSOSIpSet(TSHttpTxn txnp, unsigned int i
   HttpTransact::State *s = &(sm->t_state);
 
   s->dns_info.lookup_success = true;
-  s->host_db_info.ip() = ip;
+  ink_inet_ip4_set(s->host_db_info.ip(), ip);
 }
 
 /*

Modified: trafficserver/traffic/trunk/proxy/http/HttpSM.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpSM.cc?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpSM.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpSM.cc Wed Aug 10 23:22:53 2011
@@ -2115,11 +2115,14 @@ HttpSM::state_mark_os_down(int event, vo
       ink_assert(t_state.current.server != NULL);
       ink_assert(t_state.current.request_to == HttpTransact::ORIGIN_SERVER);
       if (t_state.current.server) {
-        mark_down = r->rr()->find_ip(t_state.current.server->ip);
+        ts_ip_endpoint ip;
+        ink_inet_ip4_set(&ip.sa, t_state.current.server->ip);
+        mark_down = r->rr()->find_ip(&ip.sa);
+//        mark_down = r->rr()->find_ip(t_state.current.server->ip);
       }
     } else {
       // No longer a round robin, check to see if our address is the same
-      if (t_state.host_db_info.ip() == r->ip()) {
+      if (ink_inet_eq(t_state.host_db_info.ip(), r->ip())) {
         mark_down = r;
       }
     }
@@ -3770,8 +3773,9 @@ HttpSM::do_hostdb_reverse_lookup()
 
   Debug("http_seq", "[HttpSM::do_hostdb_reverse_lookup] Doing reverse DNS Lookup");
 
-  uint32_t addr = ink_inet_addr(t_state.dns_info.lookup_name);
-  Action *dns_lookup_action_handle = hostDBProcessor.getbyaddr_re(this, addr);
+  ts_ip_endpoint addr;
+  ink_inet_pton(t_state.dns_info.lookup_name, &addr.sa);
+  Action *dns_lookup_action_handle = hostDBProcessor.getbyaddr_re(this, &addr.sa);
 
   if (dns_lookup_action_handle != ACTION_RESULT_DONE) {
     ink_assert(!pending_action);
@@ -3792,7 +3796,9 @@ HttpSM::do_hostdb_update_if_necessary()
   }
   // If we failed back over to the origin server, we don't have our
   //   hostdb information anymore which means we shouldn't update the hostdb
-  if (t_state.current.server->ip != t_state.host_db_info.ip()) {
+  ts_ip_endpoint ip;
+  ink_inet_ip4_set(&ip.sa, t_state.current.server->ip);
+  if (!ink_inet_eq(&ip.sa, t_state.host_db_info.ip())) {
     Debug("http", "[%" PRId64 "] skipping hostdb update due to server failover", sm_id);
     return;
   }
@@ -3830,8 +3836,12 @@ HttpSM::do_hostdb_update_if_necessary()
   }
 
   if (issue_update) {
-    hostDBProcessor.setby(t_state.current.server->name, 0,
-                          t_state.current.server->port, t_state.current.server->ip, &t_state.host_db_info.app);
+    ts_ip_endpoint ip;
+    hostDBProcessor.setby(t_state.current.server->name,
+      strlen(t_state.current.server->name),
+      ink_inet_ip4_set(&ip.sa, t_state.current.server->ip, t_state.current.server->port),
+      &t_state.host_db_info.app
+    );
   }
 
   return;
@@ -6411,7 +6421,7 @@ HttpSM::set_next_state()
            by the 'use_client_target_addr' configuration parameter.
         */
         Debug("dns", "[HttpTransact::HandleRequest] Skipping DNS lookup for client supplied target %u.%u.%u.%u.\n", PRINT_IP(addr));
-        t_state.host_db_info.ip() = addr;
+        ink_inet_ip4_set(t_state.host_db_info.ip(), addr);
         t_state.dns_info.lookup_success = true;
         call_transact_and_set_next_state(NULL);
         break;

Modified: trafficserver/traffic/trunk/proxy/http/HttpTransact.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpTransact.cc?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpTransact.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpTransact.cc Wed Aug 10 23:22:53 2011
@@ -1409,7 +1409,7 @@ HttpTransact::PPDNSLookup(State* s)
     }
   } else {
     // lookup succeeded, open connection to p.p.
-    s->parent_info.ip = s->host_db_info.ip();
+    s->parent_info.ip = ink_inet_ip4_addr_cast(s->host_db_info.ip());
     get_ka_info_from_host_db(s, &s->parent_info, &s->client_info, &s->host_db_info);
     s->parent_info.dns_round_robin = s->dns_info.round_robin;
 
@@ -1463,7 +1463,7 @@ HttpTransact::ReDNSRoundRobin(State* s)
 
     // Our ReDNS of the server succeeeded so update the necessary
     //  information and try again
-    s->server_info.ip = s->host_db_info.ip();
+    s->server_info.ip =ink_inet_ip4_addr_cast( s->host_db_info.ip());
     s->request_data.dest_ip = s->server_info.ip;
     get_ka_info_from_host_db(s, &s->server_info, &s->client_info, &s->host_db_info);
     s->server_info.dns_round_robin = s->dns_info.round_robin;
@@ -1605,7 +1605,7 @@ HttpTransact::OSDNSLookup(State* s)
   // Check to see if can fullfill expect requests based on the cached
   // update some state variables with hostdb information that has
   // been provided.
-  s->server_info.ip = s->host_db_info.ip();
+  s->server_info.ip = ink_inet_ip4_addr_cast(s->host_db_info.ip());
   s->request_data.dest_ip = s->server_info.ip;
   get_ka_info_from_host_db(s, &s->server_info, &s->client_info, &s->host_db_info);
   s->server_info.dns_round_robin = s->dns_info.round_robin;
@@ -3575,7 +3575,8 @@ HttpTransact::delete_srv_entry(State* s,
 
   MUTEX_TRY_LOCK(lock, bucket_mutex, thread);
   if (lock) {
-    HostDBInfo *r = probe(bucket_mutex, md5, hostname, len, 1, port, pDS, false, true);
+    ts_ip_endpoint ip;
+    HostDBInfo *r = probe(bucket_mutex, md5, hostname, len, ink_inet_ip4_set(&ip.sa, INADDR_ANY, htons(port)), pDS, false, true);
     if (r) {
       if (r->is_srv) {
         Debug("dns_srv", "Marking SRV records for %s [Origin: %s] as bad", hostname, s->dns_info.lookup_name);
@@ -3625,7 +3626,7 @@ HttpTransact::delete_srv_entry(State* s,
 
         new_r->ip_timeout_interval = 45;        /* good for 45 seconds, then lets re-validate? */
         new_r->ip_timestamp = hostdb_current_interval;
-        new_r->ip() = 1;
+        ink_inet_invalidate(new_r->ip());
 
         /* these go into the RR area */
         int n = new_r->srv_count;
@@ -3640,7 +3641,7 @@ HttpTransact::delete_srv_entry(State* s,
           int i = 0;
           while ((srv_entry = still_ok_hosts.dequeue())) {
             Debug("dns_srv", "Re-adding %s to HostDB [as a RR] after %s failed", srv_entry->getHost(), s->dns_info.lookup_name);
-            rr_data->info[i].ip() = 1;
+            ink_inet_invalidate(rr_data->info[i].ip());
             rr_data->info[i].round_robin = 0;
             rr_data->info[i].reverse_dns = 0;
 
@@ -6695,7 +6696,7 @@ HttpTransact::will_this_request_self_loo
   if (s->dns_info.lookup_success) {
     int dns_host_ip, host_port, local_ip, local_port;
 
-    dns_host_ip = s->host_db_info.ip();
+    dns_host_ip = ink_inet_ip4_addr_cast(s->host_db_info.ip());
     local_ip = this_machine()->ip;
 
     if (dns_host_ip == local_ip) {

Modified: trafficserver/traffic/trunk/proxy/logging/LogCollationClientSM.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogCollationClientSM.cc?rev=1156401&r1=1156400&r2=1156401&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogCollationClientSM.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogCollationClientSM.cc Wed Aug 10 23:22:53 2011
@@ -313,9 +313,9 @@ LogCollationClientSM::client_dns(int eve
       return client_done(LOG_COLL_EVENT_SWITCH, NULL);
     }
     // careful!!! could have problems later!!!
-    m_log_host->m_ip = hostdb_info->ip();
-    m_log_host->m_ipstr = (char *) xmalloc(32);
-    LogUtils::ip_to_str(m_log_host->m_ip, m_log_host->m_ipstr, 32);
+    m_log_host->m_ip = ink_inet_ip4_addr_cast(hostdb_info->ip());
+    m_log_host->m_ipstr = (char *) xmalloc(INET6_ADDRSTRLEN);
+    ink_inet_ntop(hostdb_info->ip(), m_log_host->m_ipstr, INET6_ADDRSTRLEN);
 
     return client_open(LOG_COLL_EVENT_SWITCH, NULL);