Index: trunk/src/sh_tools.c
===================================================================
--- trunk/src/sh_tools.c	(revision 425)
+++ trunk/src/sh_tools.c	(revision 472)
@@ -93,4 +93,6 @@
 #undef  FIL__
 #define FIL__  _("sh_tools.c")
+
+static int tools_debug = 0;
 
 #ifdef SH_ENCRYPT
@@ -564,4 +566,7 @@
   SL_ENTER(_("connect_port"));
 
+  if (tools_debug)
+    fprintf(stderr, _("-00- <%s> <%d> no IPv6 support\n"), address, port);
+
   if (errsiz > 0) errmsg[0] = '\0';
 
@@ -575,4 +580,8 @@
       while (check_cache && check_cache->address)
 	{
+          if (tools_debug)
+            fprintf(stderr, _("-01- <%s> <%s>\n"), 
+                    address, check_cache->address);
+
 	  if ( 0 == sl_strncmp(check_cache->address, 
 			       address, sl_strlen(address)) )
@@ -584,4 +593,14 @@
 	      break;
 	    }
+	  if (tools_debug)
+	    {
+	      char eaddr[SH_IP_BUF];
+	      sl_strlcpy(eaddr, 
+			 inet_ntoa(*(struct in_addr *) &(sinr.sin_addr)), 
+			 sizeof(eaddr));
+	      fprintf(stderr, _("-02- <AF_INET> <%s> <%d> <%d>\n"), 
+		      eaddr,
+		      port, cached);
+	    }
 	  if (check_cache->next)
 	    check_cache = check_cache->next;
@@ -595,4 +614,6 @@
   if (cached == 0)
     {
+      if (tools_debug)
+        fputs(_("-03- not cached\n"), stderr); 
 #ifdef HAVE_INET_ATON
       if (0 == inet_aton(address, &haddr))
@@ -625,4 +646,11 @@
 	      sinr.sin_addr   = *(struct in_addr *) host_entry->h_addr;
 
+	      if (tools_debug)
+                fprintf(stderr, 
+			_("-04- <%s> <%s> hostent->h_name %s <%s> hostent->h_addr\n"), 
+                        address, 
+			(host_entry->h_name == NULL) ? _("NULL") : host_entry->h_name,
+			(host_entry->h_addrtype == AF_INET) ? _("AF_INET") : _("AF_INET6"),
+			inet_ntoa(*(struct in_addr *) &(sinr.sin_addr)));
 
 	      /* reverse DNS lookup
@@ -688,4 +716,10 @@
 	  sinr.sin_port   = htons (port);
 	  sinr.sin_addr   = haddr;
+
+	  if (tools_debug)
+	    fprintf(stderr, 
+		    _("-04- <%s> is_numeric AF_INET <%s> \n"), 
+		    address, 
+		    inet_ntoa(*(struct in_addr *) &(sinr.sin_addr)));
 	}
 
@@ -743,4 +777,7 @@
 	*errnum = status;
 	sl_strlcpy(errmsg, sh_error_message (status, errbuf, sizeof(errbuf)), errsiz);
+	sl_strlcat(errmsg, 
+		   (sinr.sin_family == AF_INET) ? _(", AF_INET ") : _(", AF_INET6 "),
+		   errsiz);
 	sl_strlcat(errmsg, _(", address "), errsiz);
 	sl_strlcat(errmsg, address, errsiz);
@@ -776,8 +813,15 @@
     delete_cache();
 
+  if (tools_debug)
+    fprintf(stderr, _("-00- <%s> <%d>\n"), address, port);
+
   if (check_cache != NULL)
     {
       while (check_cache && check_cache->address)
 	{
+	  if (tools_debug)
+	    fprintf(stderr, _("-01- <%s> <%s>\n"), 
+		    address, check_cache->address);
+
 	  if ( 0 == sl_strcmp(check_cache->address, address) )
 	    {
@@ -798,4 +842,13 @@
 		  break;
 		}
+	      if (tools_debug)
+		{
+		  char eaddr[SH_IP_BUF];
+		  sh_ipvx_ntoa(eaddr, sizeof(eaddr), &ss);
+		  fprintf(stderr, _("-02- <%s> <%s> <%d> <%d>\n"), 
+			  (ss.ss_family == AF_INET) ? _("AF_INET") : _("AF_INET6"),
+			  eaddr,
+			  port, cached);
+		}
 	      break;
 	    }
@@ -809,4 +862,6 @@
   if (cached != 0)
     {
+      if (tools_debug)
+	fputs(_("-03- cached\n"), stderr); 
       fd = socket(ss.ss_family, SOCK_STREAM, 0);
       if (fd < 0) 
@@ -854,4 +909,7 @@
       struct addrinfo hints;
 
+      if (tools_debug)
+	fputs(_("-03- not cached\n"), stderr);
+
       memset (&hints, '\0', sizeof (hints));
       hints.ai_flags = AI_ADDRCONFIG;
@@ -882,15 +940,25 @@
 	  const char * canonical;
 
+
 #if defined(AI_CANONNAME)
 	  if (ai->ai_canonname && strlen(ai->ai_canonname) > 0)
 	    {
 	      canonical = ai->ai_canonname;
+	      if (tools_debug)
+		fprintf(stderr, _("-04- <%s> <%s> ai->ai_canonname\n"), 
+			address, canonical);
 	    }
 	  else
 	    {
 	      canonical = address;
+	      if (tools_debug)
+		fprintf(stderr, _("-04- <%s> <%s> defined ai_canonname\n"), 
+			address, canonical);
 	    }
 #else
 	  canonical = address;
+	  if (tools_debug)
+	    fprintf(stderr, _("-04- <%s> <%s> not defined ai_canonname\n"), 
+		    address, canonical);
 #endif
 
@@ -903,9 +971,21 @@
 	      if (e == 0)
 		{
+		  if (tools_debug)
+		    {
+		      fprintf(stderr, _("-05- <%s> <%s> <%s>\n"), 
+			      (p->ai_family == AF_INET) ? _("AF_INET") : _("AF_INET6"),
+			      sh_ipvx_print_sockaddr (p->ai_addr, p->ai_family),
+			      hostname);
+		    }
+
 		  if (sl_strcasecmp(hostname, canonical) == 0)
 		    {
+		      if (tools_debug)
+			fprintf(stderr, _("-06- <%s> <%s> match\n"), 
+				hostname, canonical);
 		      success = 1;
 		      break;
 		    }
+
 		}
 	    
@@ -1418,8 +1498,8 @@
       SH_IS_ASCII(head[5]) && isalpha(head[5]) &&			   
       SH_IS_ASCII(head[6]) && isalpha(head[6])) {
-    fprintf(stderr, "%c %3o %s %5d  %c  %c  %c  %c\n", sign,
+    fprintf(stderr, _("%c %3o %s %5d  %c  %c  %c  %c\n"), sign,
 	    head[0], code, msg_size, head[3], head[4], head[5], head[6]); 
   } else {
-    fprintf(stderr, "%c %3o %s %5d %2X %2X %2X %2X\n", sign,
+    fprintf(stderr, _("%c %3o %s %5d %2X %2X %2X %2X\n"), sign,
 	    head[0], code, msg_size, head[3], head[4], head[5], head[6]); 
   }
