commit ae37faa3d620928c478b85ceaac571a2467ec305
Author: Bertram Felgenhauer <int-e@gmx.de>
Date:   Sun Feb 8 21:49:28 2009 +0100

    some USE_IPV6 cleanups
    
    - if gethostbyname returns an IPv4 address for our host, convert it to IPv6
    - use proper structs for IPv6 addresses (template and local name)
    
    Note: This patch is by no means comprehensive. The whole IPv6 support needs
    a review.

diff --git a/src/comm.c b/src/comm.c
index 0cd14c4..aa487b6 100644
--- a/src/comm.c
+++ b/src/comm.c
@@ -352,12 +352,20 @@ static char host_name[MAXHOSTNAMELEN+1];
   /* This computer's hostname, used for query_host_name() efun.
    */
 
+#ifdef USE_IPV6
+static struct in6_addr host_ip_number;
+#else
 static struct in_addr host_ip_number;
+#endif
   /* This computer's numeric IP address only, used for
    * the query_host_ip_number() efun.
    */
 
+#ifdef USE_IPV6
+static struct sockaddr_in6 host_ip_addr_template;
+#else
 static struct sockaddr_in host_ip_addr_template;
+#endif
   /* The template address of this computer. It is copied locally
    * and augmented with varying port numbers to open the driver's ports.
    */
@@ -514,8 +522,7 @@ static INLINE ssize_t comm_send_buf(char *msg, size_t size, interactive_t *ip);
 static inline void CREATE_IPV6_MAPPED(struct in_addr *v6, uint32 v4) {
   v6->s6_addr32[0] = 0;
   v6->s6_addr32[1] = 0;
-  v6->s6_addr32[2] = 0x0000ffff;
-  v6->s6_addr32[2] = 0xffff0000;
+  v6->s6_addr32[2] = htonl(0x0000ffff);
   v6->s6_addr32[3] = v4;
 }
 
@@ -1001,9 +1008,17 @@ initialize_host_ip_number (const char *hname, const char * haddr)
                           , time_stamp(), host_name);
             exit(1);
         }
+#ifdef USE_IPV6
+        if (hp->h_addrtype == AF_INET6) {
+            memcpy(&host_ip_addr_template.sin_addr, hp->h_addr, (size_t)hp->h_length);
+            host_ip_number = host_ip_addr_template.sin_addr;
+        } else {
+            CREATE_IPV6_MAPPED(&host_ip_number, *(uint32_t *)hp->h_addr);
+        }
+#else
         memcpy(&host_ip_addr_template.sin_addr, hp->h_addr, (size_t)hp->h_length);
-        host_ip_addr_template.sin_family = (unsigned short)hp->h_addrtype;
         host_ip_number = host_ip_addr_template.sin_addr;
+#endif
 
         /* Now set the template to the proper _ANY value */
         memset(&host_ip_addr_template.sin_addr, 0, sizeof(host_ip_addr_template.sin_addr));
