diff -uN X11R6-orig/xc/lib/SM/sm_genid.c X11R6-new/xc/lib/SM/sm_genid.c
--- X11R6-orig/xc/lib/SM/sm_genid.c
+++ X11R6-new/xc/lib/SM/sm_genid.c
@@ -63,6 +63,7 @@
 #define XOS_USE_NO_LOCKING
 #define X_INCLUDE_NETDB_H
 #include <X11/Xos_r.h>
+#include <resolv.h>
 #endif
 
 #else /* WIN32 */
@@ -136,6 +137,7 @@
 
 #if defined(TCPCONN) || defined(STREAMSCONN)
     {
+    u_long options;
     char* inet_addr;
     char temp[4], *ptr1, *ptr2;
     unsigned char decimal[4];
@@ -143,7 +145,13 @@
     _Xgethostbynameparams hparams;
     struct hostent *hostp;
 
-    if ((hostp = _XGethostbyname (hostname,hparams)) != NULL)
+    if ((_res.options & RES_INIT) == 0)
+	(void) res_init ();
+    options = _res.options;
+    _res.options &= ~RES_USE_INET6;
+    hostp = _XGethostbyname (hostname,hparams);
+    _res.options = options;
+    if (hostp != NULL)
 	inet_addr = (char *) inet_ntoa (*(struct in_addr *)(hostp->h_addr));
     else
 	return NULL;
diff -uN X11R6-orig/xc/lib/X11/ConnDis.c X11R6-new/xc/lib/X11/ConnDis.c
--- X11R6-orig/xc/lib/X11/ConnDis.c
+++ X11R6-new/xc/lib/X11/ConnDis.c
@@ -334,7 +334,7 @@
 	_X11TransGetPeerAddr(trans_conn, &family, &saddrlen, &saddr);
 
 	/*
-	 * The family is given in a socket format (ie AF_INET). This
+	 * The family is given in a socket format (ie AF_INET[6]). This
 	 * will convert it to the format used by the authorization and
 	 * X protocol (ie FamilyInternet).
 	 */
@@ -1026,6 +1026,21 @@
 	    for(i=4; i<8; i++)	/* do sin_addr */
 		xdmcp_data[j++] = ((char *)addr)[i];
 	    for(i=2; i<4; i++)	/* do sin_port */
+		xdmcp_data[j++] = ((char *)addr)[i];
+	    break;
+	}
+#endif /* AF_INET */
+#ifdef AF_INET6
+	case AF_INET6:
+	{
+	    /*
+	     * addr will contain a sockaddr_in6 with all
+	     * of the members already in network byte order.
+	     */
+
+	    for(i=20; i<24; i++) /* do sin6_addr last 4 bytes */
+		xdmcp_data[j++] = ((char *)addr)[i];
+	    for(i=2; i<4; i++)	/* do sin6_port */
 		xdmcp_data[j++] = ((char *)addr)[i];
 	    break;
 	}
diff -uN X11R6-orig/xc/lib/Xmu/CvtStdSel.c X11R6-new/xc/lib/Xmu/CvtStdSel.c
--- X11R6-orig/xc/lib/Xmu/CvtStdSel.c
+++ X11R6-new/xc/lib/Xmu/CvtStdSel.c
@@ -225,7 +225,9 @@
 	if ((hostp = _XGethostbyname (hostname,hparams)) == NULL)
 	    return False;
 
-	if (hostp->h_addrtype != AF_INET) return False;
+	if ((hostp->h_addrtype != AF_INET) &&
+	    (hostp->h_addrtype != AF_INET6))
+	    return False;
 	*length = hostp->h_length;
 	*value = XtMalloc(*length);
 	(void) memmove (*value, hostp->h_addr, *length);
diff -uN X11R6-orig/xc/lib/xtrans/Xtranssock.c X11R6-new/xc/lib/xtrans/Xtranssock.c
--- X11R6-orig/xc/lib/xtrans/Xtranssock.c
+++ X11R6-new/xc/lib/xtrans/Xtranssock.c
@@ -70,6 +70,7 @@
 #define X_INCLUDE_NETDB_H
 #define XOS_USE_NO_LOCKING
 #include <X11/Xos_r.h>
+#include <resolv.h>
 #endif
 
 #ifdef UNIXCONN
@@ -190,8 +191,8 @@
 
 static Sockettrans2dev Sockettrans2devtab[] = {
 #ifdef TCPCONN
-    {"inet",AF_INET,SOCK_STREAM,SOCK_DGRAM,0},
-    {"tcp",AF_INET,SOCK_STREAM,SOCK_DGRAM,0},
+    {"inet",AF_INET6,SOCK_STREAM,SOCK_DGRAM,0},
+    {"tcp",AF_INET6,SOCK_STREAM,SOCK_DGRAM,0},
 #endif /* TCPCONN */
 #ifdef UNIXCONN
     {"unix",AF_UNIX,SOCK_STREAM,SOCK_DGRAM,0},
@@ -294,7 +295,7 @@
 XtransConnInfo ciptr;
 
 {
-    struct sockaddr_in 	sockname;
+    struct sockaddr_in6	sockname;
 #if defined(SVR4) || defined(SCO325)
     size_t namelen = sizeof sockname;
 #else
@@ -322,7 +323,7 @@
         return -1;
     }
 
-    ciptr->family = sockname.sin_family;
+    ciptr->family = sockname.sin6_family;
     ciptr->addrlen = namelen;
     memcpy (ciptr->addr, &sockname, ciptr->addrlen);
 
@@ -341,7 +342,7 @@
 XtransConnInfo ciptr;
 
 {
-    struct sockaddr_in 	sockname;
+    struct sockaddr_in6	sockname;
 #if defined(SVR4) || defined(SCO325)
     size_t namelen = sizeof sockname;
 #else
@@ -410,10 +411,11 @@
     }
 
 #ifdef TCP_NODELAY
-    if (Sockettrans2devtab[i].family == AF_INET)
+    if ((Sockettrans2devtab[i].family == AF_INET) ||
+	(Sockettrans2devtab[i].family == AF_INET6))
     {
 	/*
-	 * turn off TCP coalescence for INET sockets
+	 * turn off TCP coalescence for INET[6] sockets
 	 */
 
 	int tmp = 1;
@@ -546,10 +548,11 @@
 #ifdef SO_REUSEADDR
 
     /*
-     * SO_REUSEADDR only applied to AF_INET
+     * SO_REUSEADDR only applied to AF_INET6
      */
 
-    if (Sockettrans2devtab[i].family == AF_INET)
+    if ((Sockettrans2devtab[i].family == AF_INET) ||
+	(Sockettrans2devtab[i].family == AF_INET6))
     {
 	int one = 1;
 	setsockopt (ciptr->fd, SOL_SOCKET, SO_REUSEADDR,
@@ -770,7 +773,8 @@
 
     PRMSG (3, "SocketCreateListener(%x,%d)\n", ciptr, fd, 0);
 
-    if (Sockettrans2devtab[ciptr->index].family == AF_INET)
+    if ((Sockettrans2devtab[ciptr->index].family == AF_INET) ||
+	(Sockettrans2devtab[ciptr->index].family == AF_INET6))
 	retry = 20;
     else
 	retry = 0;
@@ -793,7 +797,8 @@
 #endif /* SO_REUSEDADDR */
     }
 
-    if (Sockettrans2devtab[ciptr->index].family == AF_INET) {
+    if ((Sockettrans2devtab[ciptr->index].family == AF_INET) ||
+	(Sockettrans2devtab[ciptr->index].family == AF_INET)) {
 #ifdef SO_DONTLINGER
 	setsockopt (fd, SOL_SOCKET, SO_DONTLINGER, (char *) NULL, 0);
 #else
@@ -830,7 +835,7 @@
 char 		*port;
 
 {
-    struct sockaddr_in	sockname;
+    struct sockaddr_in6	sockname;
     int		namelen = sizeof(sockname);
     int		status;
     short	tmpport;
@@ -878,22 +883,23 @@
 		      port, 0, 0);
 		return TRANS_CREATE_LISTENER_FAILED;
 	    }
-	    sockname.sin_port = servp->s_port;
+	    sockname.sin6_port = servp->s_port;
 	}
 	else
 	{
 	    tmpport = (short) atoi (port);
-	    sockname.sin_port = htons (tmpport);
+	    sockname.sin6_port = htons (tmpport);
 	}
     }
     else
-	sockname.sin_port = htons (0);
+	sockname.sin6_port = htons (0);
 
 #ifdef BSD44SOCKETS
-    sockname.sin_len = sizeof (sockname);
+    sockname.sin6_len = sizeof (sockname);
 #endif
-    sockname.sin_family = AF_INET;
-    sockname.sin_addr.s_addr = htonl (INADDR_ANY);
+    sockname.sin6_family = AF_INET6;
+    sockname.sin6_flowinfo = 0;
+    sockname.sin6_addr = in6addr_any;
 
     if ((status = TRANS(SocketCreateListener) (ciptr,
 	(struct sockaddr *) &sockname, namelen)) < 0)
@@ -1077,7 +1083,7 @@
 
 {
     XtransConnInfo	newciptr;
-    struct sockaddr_in	sockname;
+    struct sockaddr_in6	sockname;
     int			namelen = sizeof(sockname);
 
     PRMSG (2, "SocketINETAccept(%x,%d)\n", ciptr, ciptr->fd, 0);
@@ -1240,7 +1246,7 @@
 char 		*port;
 
 {
-    struct sockaddr_in	sockname;
+    struct sockaddr_in6	sockname;
 #if defined(SVR4) || defined(SCO325)
     size_t namelen = sizeof sockname;
 #else
@@ -1250,14 +1256,15 @@
     _Xgetservbynameparams sparams;
     struct hostent	*hostp;
     struct servent	*servp;
+    u_long options;
 
 #define PORTBUFSIZE	64	/* what is a real size for this? */
     char	portbuf[PORTBUFSIZE];
 
     int			ret;
     short		tmpport;
-    unsigned long 	tmpaddr;
     char 		hostnamebuf[256];		/* tmp space */
+    char		v[64];				/* Vixie's tmp space */
 
     PRMSG (2,"SocketINETConnect(%d,%s,%s)\n", ciptr->fd, host, port);
 
@@ -1293,67 +1300,44 @@
      */
 
 #ifdef BSD44SOCKETS
-    sockname.sin_len = sizeof (struct sockaddr_in);
+    sockname.sin6_len = sizeof (struct sockaddr_in6);
 #endif
-    sockname.sin_family = AF_INET;
+    sockname.sin6_family = AF_INET6;
+    sockname.sin6_flowinfo = 0;
 
     /*
-     * fill in sin_addr
+     * fill in sin6_addr
      */
 
-    /* check for ww.xx.yy.zz host string */
-
-    if (isascii (host[0]) && isdigit (host[0])) {
-	tmpaddr = inet_addr (host); /* returns network byte order */
-    } else {
-	tmpaddr = -1;
-    }
-
-    PRMSG (4,"SocketINETConnect: inet_addr(%s) = %x\n",
-	host, tmpaddr, 0);
+    /* ww.xx.yy.zz host string done by _XGethostbyname() */
 
-    if (tmpaddr == -1)
-    {
-	if ((hostp = _XGethostbyname(host,hparams)) == NULL)
-	{
-	    PRMSG (1,"SocketINETConnect: Can't get address for %s\n",
-		  host, 0, 0);
-	    ESET(EINVAL);
-	    return TRANS_CONNECT_FAILED;
-	}
-	if (hostp->h_addrtype != AF_INET)  /* is IP host? */
-	{
-	    PRMSG (1,"SocketINETConnect: not INET host%s\n",
-		  host, 0, 0);
-	    ESET(EPROTOTYPE);
-	    return TRANS_CONNECT_FAILED;
-	}
-	
-#if defined(CRAY) && defined(OLDTCP)
-        /* Only Cray UNICOS3 and UNICOS4 will define this */
-        {
-	long t;
-	memcpy ((char *)&t, (char *) hostp->h_addr, sizeof (t));
-	sockname.sin_addr = t;
-        }
-#else
-        memcpy ((char *) &sockname.sin_addr, (char *) hostp->h_addr,
-		sizeof (sockname.sin_addr));
-#endif /* CRAY and OLDTCP */
-	
+    if ((_res.options & RES_INIT) == 0)
+	(void)res_init();
+    options = _res.options;
+    _res.options |= RES_USE_INET6;
+
+    hostp = _XGethostbyname(host,hparams);
+    _res.options = options;
+    if (hostp == NULL)
+    {
+	PRMSG (1,"SocketINETConnect: Can't get address for %s\n",
+	       host, 0, 0);
+	ESET(EINVAL);
+	return TRANS_CONNECT_FAILED;
     }
-else
+    if (hostp->h_addrtype != AF_INET6)  /* is IPv6 host? */
     {
-#if defined(CRAY) && defined(OLDTCP)
-	/* Only Cray UNICOS3 and UNICOS4 will define this */
-	sockname.sin_addr = tmpaddr;
-#else
-	sockname.sin_addr.s_addr = tmpaddr;
-#endif /* CRAY and OLDTCP */
+	PRMSG (1,"SocketINETConnect: not INET host%s\n",
+	       host, 0, 0);
+	ESET(EPROTOTYPE);
+	return TRANS_CONNECT_FAILED;
     }
+	
+    memcpy ((char *) &sockname.sin6_addr, (char *) hostp->h_addr,
+		sizeof (sockname.sin6_addr));
 
     /*
-     * fill in sin_port
+     * fill in sin6_port
      */
     
     /* Check for number in the port string */
@@ -1366,16 +1350,16 @@
 		  portbuf, 0, 0);
 	    return TRANS_CONNECT_FAILED;
 	}
-	sockname.sin_port = servp->s_port;
+	sockname.sin6_port = servp->s_port;
     }
     else
     {
 	tmpport = (short) atoi (portbuf);
-	sockname.sin_port = htons (tmpport);
+	sockname.sin6_port = htons (tmpport);
     }
     
-    PRMSG (4,"SocketINETConnect: sockname.sin_port = %d\n",
-	  ntohs(sockname.sin_port), 0, 0);
+    PRMSG (4,"SocketINETConnect: sockname.sin6_port = %d\n",
+	  ntohs(sockname.sin6_port), 0, 0);
 
     /*
      * Do the connect()
@@ -1463,13 +1447,21 @@
 	 * by TRANS(GetHostname)), then the two hostnames are equivalent,
 	 * and we know that 'host' is really a local host.
 	 */
-	char specified_local_addr_list[10][4];
+	char specified_local_addr_list[10][16];
 	int scount, equiv, i, j;
 	_Xgethostbynameparams hparams;
 	struct hostent *hostp;
+	u_long options;
 
-	if ((hostp = _XGethostbyname (host,hparams)) == NULL)
+	if ((_res.options & RES_INIT) == 0)
+	    (void)res_init();
+	options = _res.options;
+	_res.options |= RES_USE_INET6;
+
+	if ((hostp = _XGethostbyname (host,hparams)) == NULL) {
+	    _res.options = options;
 	    return (0);
+	}
 
 	scount = 0;
 	while (hostp->h_addr_list[scount] && scount <= 8)
@@ -1479,17 +1471,14 @@
 	     * from the 1st call, so we must save the address list.
 	     */
 
-	    specified_local_addr_list[scount][0] = 
-				hostp->h_addr_list[scount][0];
-	    specified_local_addr_list[scount][1] = 
-				hostp->h_addr_list[scount][1];
-	    specified_local_addr_list[scount][2] = 
-				hostp->h_addr_list[scount][2];
-	    specified_local_addr_list[scount][3] = 
-				hostp->h_addr_list[scount][3];
+	    memcpy(specified_local_addr_list[scount],
+		   hostp->h_addr_list[scount],
+		   hostp->h_length);
 	    scount++;
 	}
-	if ((hostp = _XGethostbyname (hostnamebuf,hparams)) == NULL)
+	hostp = _XGethostbyname (hostnamebuf,hparams);
+	_res.options = options;
+	if (hostp == NULL)
 	    return (0);
 
 	equiv = 0;
@@ -1501,14 +1490,9 @@
 
 	    while (hostp->h_addr_list[j])
 	    {
-		if ((specified_local_addr_list[i][0] == 
-					hostp->h_addr_list[j][0]) &&
-		    (specified_local_addr_list[i][1] == 
-					hostp->h_addr_list[j][1]) &&
-		    (specified_local_addr_list[i][2] == 
-					hostp->h_addr_list[j][2]) &&
-		    (specified_local_addr_list[i][3] == 
-					hostp->h_addr_list[j][3]))
+		if (memcmp(specified_local_addr_list[i],
+			   hostp->h_addr_list[j],
+			   hostp->h_length) == 0)
 		{
 		    /* They're equal, so we're done */
 		    
diff -uN X11R6-orig/xc/lib/xtrans/Xtransutil.c X11R6-new/xc/lib/xtrans/Xtransutil.c
--- X11R6-orig/xc/lib/xtrans/Xtransutil.c
+++ X11R6-new/xc/lib/xtrans/Xtransutil.c
@@ -84,7 +84,7 @@
 /*
  * TRANS(ConvertAddress) converts a sockaddr based address to an
  * X authorization based address. Some of this is defined as part of
- * the ChangeHost protocol. The rest is just doen in a consistent manner.
+ * the ChangeHost protocol. The rest is just done in a consistent manner.
  */
 
 int
@@ -134,6 +134,32 @@
 	}
 	break;
     }
+
+    case AF_INET6:
+    {
+	/*
+	 * Check for the hack localhost address ::1.
+	 * In this case, we are really FamilyLocal.
+	 */
+
+	struct sockaddr_in6 saddr;
+	int len = sizeof(saddr.sin6_addr);
+	char *cp = (char *) &saddr.sin6_addr;
+
+	memcpy (&saddr, *addrp, sizeof (struct sockaddr_in6));
+
+	if (memcmp(cp, (char *)&in6addr_loopback, len) == 0)
+	{
+	    *familyp=FamilyLocal;
+	}
+	else
+	{
+	    *familyp=FamilyInternet;
+	    *addrlenp=len;
+	    memcpy(*addrp,&saddr.sin6_addr,len);
+	}
+	break;
+    }
 #endif /* defined(TCPCONN) || defined(STREAMSCONN) || MNX_TCPCONN */
 
 #if defined(DNETCONN)
@@ -269,6 +295,18 @@
 	sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, portnumbuf);
 	break;
     }
+
+    case AF_INET6:
+    {
+	struct sockaddr_in6 *saddr = (struct sockaddr_in6 *) addr;
+	char portnumbuf[10];
+
+	sprintf (portnumbuf, "%d", ntohs (saddr->sin6_port));
+	networkId = (char *) xalloc (3 + strlen (transName) +
+	    strlen (hostnamebuf) + strlen (portnumbuf));
+	sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, portnumbuf);
+	break;
+    }
 #endif /* defined(TCPCONN) || defined(STREAMSCONN) || MNX_TCPCONN */
 
 #if defined(DNETCONN)
@@ -377,6 +415,42 @@
 	  addr = hostp->h_name;
 	else
 	  addr = inet_ntoa (saddr->sin_addr);
+	break;
+    }
+
+    case AF_INET6:
+    {
+	struct sockaddr_in6 *saddr = (struct sockaddr_in6 *) peer_addr;
+	_Xgethostbynameparams hparams;
+	struct hostent * hostp;
+	static char v[64];
+
+#ifdef SIGALRM
+	/*
+	 * gethostbyaddr can take a LONG time if the host does not exist.
+	 * Assume that if it does not respond in NAMESERVER_TIMEOUT seconds
+	 * that something is wrong and do not make the user wait.
+	 * gethostbyaddr will continue after a signal, so we have to
+	 * jump out of it. 
+	 */
+
+	nameserver_timedout = 0;
+	signal (SIGALRM, nameserver_lost);
+	alarm (4);
+	if (setjmp(env) == 0) {
+#endif
+	    hostp = _XGethostbyaddr ((char *) &saddr->sin6_addr,
+		sizeof (saddr->sin6_addr), AF_INET6, hparams);
+#ifdef SIGALRM
+	}
+	alarm (0);
+#endif
+	if (hostp != NULL)
+	  addr = hostp->h_name;
+	else {
+	  inet_ntop (AF_INET6, &saddr->sin6_addr, v, sizeof (v));
+	  addr = addrbuf;
+	}
 	break;
     }
 
diff -uN X11R6-orig/xc/programs/xdm/auth.c X11R6-new/xc/programs/xdm/auth.c
--- X11R6-orig/xc/programs/xdm/auth.c
+++ X11R6-new/xc/programs/xdm/auth.c
@@ -976,9 +976,7 @@
 	     * the local entry anyway, so this one can
 	     * be tossed.
 	     */
-	    if (len == 4 &&
-		addr[0] == 127 && addr[1] == 0 &&
-		addr[2] == 0 && addr[3] == 1)
+	    if (bcmp(addr, &in6addr_loopback, len) == 0)
 	    {
 		    Debug ("Skipping localhost address\n");
 		    continue;
@@ -1009,10 +1007,10 @@
 
     union {
 	struct  sockaddr   sa;
-	struct  sockaddr_in  in;
+	struct  sockaddr_in6  in;
     } saddr;
 	
-    struct	sockaddr_in	*inetaddr;
+    struct	sockaddr_in6	*inetaddr;
 
     /* hpux:
      * Why not use gethostname()?  Well, at least on my system, I've had to
@@ -1024,12 +1022,12 @@
     hp = gethostbyname (name.nodename);
     if (hp != NULL) {
 	saddr.sa.sa_family = hp->h_addrtype;
-	inetaddr = (struct sockaddr_in *) (&(saddr.sa));
-	memmove( (char *) &(inetaddr->sin_addr), (char *) hp->h_addr, (int) hp->h_length);
+	inetaddr = (struct sockaddr_in6 *) (&(saddr.sa));
+	memmove( (char *) &(inetaddr->sin6_addr), (char *) hp->h_addr, (int) hp->h_length);
 	family = ConvertAddr ( &(saddr.sa), &len, &addr);
 	if ( family >= 0) {
-	    writeAddr (FamilyInternet, sizeof (inetaddr->sin_addr),
-			(char *) (&inetaddr->sin_addr), file, auth);
+	    writeAddr (FamilyInternet, sizeof (inetaddr->sin6_addr),
+			(char *) (&inetaddr->sin6_addr), file, auth);
 	}
     }
 }
@@ -1096,7 +1094,7 @@
     	tcp_device= TCP_DEVICE;
     fd = open(tcp_device, O_RDWR);
 #else
-    fd = socket (AF_INET, SOCK_STREAM, 0);
+    fd = socket (AF_INET6, SOCK_STREAM, 0);
 #endif
     DefineSelf (fd, file, auth);
     close (fd);
diff -uN X11R6-orig/xc/programs/xdm/choose.c X11R6-new/xc/programs/xdm/choose.c
--- X11R6-orig/xc/programs/xdm/choose.c
+++ X11R6-new/xc/programs/xdm/choose.c
@@ -232,6 +232,22 @@
 	    result_len = 8;
 	}
 	break;
+    case AF_INET6:
+	{
+	    char *port;
+	    int portlen;
+	    ARRAY8Ptr localAddress, getLocalAddress ();
+
+	    port = NetaddrPort((XdmcpNetaddr)addr_buf, &portlen);
+	    result_buf[0] = netfamily >> 8;
+	    result_buf[1] = netfamily & 0xFF;
+	    result_buf[2] = port[0];
+	    result_buf[3] = port[1];
+	    localAddress = getLocalAddress ();
+	    memmove( (char *)result_buf+4, (char *)localAddress->data, 16);
+	    result_len = 20;
+	}
+	break;
 #ifdef AF_DECnet
     case AF_DECnet:
 	break;
diff -uN X11R6-orig/xc/programs/xdm/chooser.c X11R6-new/xc/programs/xdm/chooser.c
--- X11R6-orig/xc/programs/xdm/chooser.c
+++ X11R6-new/xc/programs/xdm/chooser.c
@@ -87,6 +87,7 @@
 #include    <socket.h>
 #endif
 #include    <netinet/in.h>
+#include    <resolv.h>
 #else /* MINIX */
 #include <net/hton.h>
 #include <net/netlib.h>
@@ -344,6 +345,11 @@
 	hostAddr.length = 4;
 	connectionType = FamilyInternet;
 	break;
+    case AF_INET6:
+	hostAddr.data = (CARD8 *) &((struct sockaddr_in6 *) addr)->sin6_addr;
+	hostAddr.length = 16;
+	connectionType = FamilyInternet;
+	break;
     default:
 	hostAddr.data = (CARD8 *) "";
 	hostAddr.length = 0;
@@ -373,11 +379,12 @@
 	    switch (addr->sa_family)
 	    {
 	    case AF_INET:
+	    case AF_INET6:
 	    	{
 	    	    struct hostent  *hostent;
 		    char	    *host;
     	
-	    	    hostent = gethostbyaddr ((char *)hostAddr.data, hostAddr.length, AF_INET);
+	    	    hostent = gethostbyaddr ((char *)hostAddr.data, hostAddr.length, addr->sa_family);
 	    	    if (hostent)
 	    	    {
 			XdmcpDisposeARRAY8 (hostname);
@@ -490,7 +497,7 @@
     ARRAY8	    hostname;
     ARRAY8	    status;
     int		    saveHostname = 0;
-    struct sockaddr addr;
+    struct sockaddr_in6 addr;
     int		    addrlen;
 #ifdef MINIX
     int r;
@@ -747,6 +754,7 @@
 	    in_addr.sin_family = AF_INET;
 	else
 	{
+	    /* TODO */
 	    hostent = gethostbyname (name);
 	    if (!hostent)
 		return;
@@ -917,7 +925,7 @@
     ref.ref_int= socketFD;
     nbio_setcallback(socketFD, ASIO_READ, read_cb, ref);
 #else /* !MINIX */
-    if ((socketFD = socket (AF_INET, SOCK_DGRAM, 0)) < 0)
+    if ((socketFD = socket (AF_INET6, SOCK_DGRAM, 0)) < 0)
 	return 0;
 #endif /* MINIX */
 #endif
@@ -947,7 +955,7 @@
 {
     if (app_resources.xdmAddress)
     {
-	struct sockaddr_in  in_addr;
+	struct sockaddr_in6  in_addr;
 	struct sockaddr	*addr;
 	int		family;
 	int		len;
@@ -967,13 +975,14 @@
 	xdm = (char *) app_resources.xdmAddress->data;
 	family = (xdm[0] << 8) + xdm[1];
 	switch (family) {
-	case AF_INET:
+	case AF_INET6:
 #ifdef BSD44SOCKETS
-	    in_addr.sin_len = sizeof(in_addr);
+	    in_addr.sin6_len = sizeof(in_addr);
 #endif
-	    in_addr.sin_family = family;
-	    memmove( &in_addr.sin_port, xdm + 2, 2);
-	    memmove( &in_addr.sin_addr, xdm + 4, 4);
+	    in_addr.sin6_family = family;
+	    in_addr.sin6_flowinfo = 0;
+	    memmove( &in_addr.sin6_port, xdm + 2, 2);
+	    memmove( &in_addr.sin6_addr, xdm + 4, 16);
 	    addr = (struct sockaddr *) &in_addr;
 	    len = sizeof (in_addr);
 	    break;
@@ -1169,6 +1178,10 @@
     Arg		position[3];
     Dimension   width, height;
     Position	x, y;
+
+    if ((_res.options & RES_INIT) == 0)
+	(void)res_init();
+    _res.options |= RES_USE_INET6;
 
     toplevel = XtInitialize (argv[0], "Chooser", options, XtNumber(options), &argc, argv);
 
diff -uN X11R6-orig/xc/programs/xdm/dm.c X11R6-new/xc/programs/xdm/dm.c
--- X11R6-orig/xc/programs/xdm/dm.c
+++ X11R6-new/xc/programs/xdm/dm.c
@@ -79,6 +79,8 @@
 extern int errno;
 #endif
 
+#include	<netinet/in.h>
+#include	<resolv.h>
 
 #if defined(SVR4) && !defined(SCO)
 extern FILE    *fdopen();
@@ -118,6 +120,10 @@
     Title = argv[0];
     TitleLen = (argv[argc - 1] + strlen(argv[argc - 1])) - Title;
 #endif
+
+    if ((_res.options & RES_INIT) == 0)
+	(void)res_init();
+    _res.options |= RES_USE_INET6;
 
     /*
      * Step 1 - load configuration parameters
diff -uN X11R6-orig/xc/programs/xdm/netaddr.c X11R6-new/xc/programs/xdm/netaddr.c
--- X11R6-orig/xc/programs/xdm/netaddr.c
+++ X11R6-new/xc/programs/xdm/netaddr.c
@@ -65,7 +65,7 @@
 #endif
 
 /* given an XdmcpNetaddr, returns the socket protocol family used,
-   e.g., AF_INET */
+   e.g., AF_INET[6] */
 
 int NetaddrFamily(netaddrp)
     XdmcpNetaddr netaddrp;
@@ -96,6 +96,9 @@
     case AF_INET:
 	*lenp = 2;
 	return (char *)&(((struct sockaddr_in *)netaddrp)->sin_port);
+    case AF_INET6:
+	*lenp = 2;
+	return (char *)&(((struct sockaddr_in6 *)netaddrp)->sin6_port);
     default:
 	*lenp = 0;
 	return NULL;
@@ -125,6 +128,9 @@
     case AF_INET:
         *lenp = sizeof (struct in_addr);
         return (char *) &(((struct sockaddr_in *)netaddrp)->sin_addr);
+    case AF_INET6:
+        *lenp = sizeof (struct in6_addr);
+        return (char *) &(((struct sockaddr_in6 *)netaddrp)->sin6_addr);
 #endif
 #ifdef DNETCONN
     case AF_DECnet:
@@ -177,6 +183,7 @@
 #endif
 #ifdef TCPCONN
       case AF_INET:
+      case AF_INET6:
         retval = FamilyInternet;
 	break;
 #endif
@@ -248,6 +255,20 @@
 
 	Debug ("port %d, host %d.%d.%d.%d\n",
 		(p[0] << 8) + p[1], t[0], t[1], t[2], t[3]);
+	break;
+    }
+#endif
+#ifdef AF_INET6
+    case AF_INET6:
+
+	p = (unsigned char *) &((struct sockaddr_in6 *) a)->sin6_port;
+	t = (unsigned char *) &((struct sockaddr_in6 *) a)->sin6_addr;
+
+	Debug ("port %d, host %2x%02x:%2x%02x:%2x%02x:%2x%02x:%2x%02x:%2x%02x:%2x%02x:%2x%02x\n",
+		(p[0] << 8) + p[1],
+	        t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7],
+	        t[8], t[9], t[10], t[11], t[12], t[13], t[14], t[15]);
+
 	break;
     }
 #endif
diff -uN X11R6-orig/xc/programs/xdm/socket.c X11R6-new/xc/programs/xdm/socket.c
--- X11R6-orig/xc/programs/xdm/socket.c
+++ X11R6-new/xc/programs/xdm/socket.c
@@ -84,7 +84,7 @@
 CreateWellKnownSockets ()
 {
 #ifndef MINIX
-    struct sockaddr_in	sock_addr;
+    struct sockaddr_in6	sock_addr;
 #else /* MINIX */
     char *tcp_device, *udp_device;
     nwio_udpopt_t udpopt;
@@ -103,7 +103,7 @@
     	udp_device= UDP_DEVICE;
     xdmcpFd = open(udp_device, O_RDWR);
 #else
-    xdmcpFd = socket (AF_INET, SOCK_DGRAM, 0);
+    xdmcpFd = socket (AF_INET6, SOCK_DGRAM, 0);
 #endif
     if (xdmcpFd == -1) {
 	LogError ("XDMCP socket creation failed, errno %d\n", errno);
@@ -145,11 +145,12 @@
     /* zero out the entire structure; this avoids 4.4 incompatibilities */
     bzero ((char *) &sock_addr, sizeof (sock_addr));
 #ifdef BSD44SOCKETS
-    sock_addr.sin_len = sizeof(sock_addr);
+    sock_addr.sin6_len = sizeof(sock_addr);
 #endif
-    sock_addr.sin_family = AF_INET;
-    sock_addr.sin_port = htons ((short) request_port);
-    sock_addr.sin_addr.s_addr = htonl (INADDR_ANY);
+    sock_addr.sin6_family = AF_INET6;
+    sock_addr.sin6_port = htons ((short) request_port);
+    sock_addr.sin6_flowinfo = 0;
+    sock_addr.sin6_addr = in6addr_any;
     if (bind (xdmcpFd, (struct sockaddr *)&sock_addr, sizeof (sock_addr)) == -1)
     {
 	LogError ("error %d binding socket address %d\n", errno, request_port);
@@ -167,7 +168,7 @@
     	tcp_device= TCP_DEVICE;
     chooserFd = open(tcp_device, O_RDWR);
 #else
-    chooserFd = socket (AF_INET, SOCK_STREAM, 0);
+    chooserFd = socket (AF_INET6, SOCK_STREAM, 0);
 #endif
     Debug ("Created chooser socket %d\n", chooserFd);
     if (chooserFd == -1)
@@ -216,7 +217,7 @@
     char	*addr;
     int		*lenp;
 {
-    struct sockaddr_in	in_addr;
+    struct sockaddr_in6	in_addr;
     int			len;
 
     len = sizeof in_addr;
diff -uN X11R6-orig/xc/programs/xdm/xdmcp.c X11R6-new/xc/programs/xdm/xdmcp.c
--- X11R6-orig/xc/programs/xdm/xdmcp.c
+++ X11R6-new/xc/programs/xdm/xdmcp.c
@@ -133,8 +133,8 @@
     ARRAY8Ptr	address;
     char	*closure;
 {
-#ifdef AF_INET
-    struct sockaddr_in	    in_addr;
+#ifdef AF_INET6
+    struct sockaddr_in6	    in_addr;
 #endif
 #ifdef AF_DECnet
 #endif
@@ -143,19 +143,20 @@
 
     switch (connectionType)
     {
-#ifdef AF_INET
+#ifdef AF_INET6
     case FamilyInternet:
 	addr = (struct sockaddr *) &in_addr;
 	bzero ((char *) &in_addr, sizeof (in_addr));
 #ifdef BSD44SOCKETS
-	in_addr.sin_len = sizeof(in_addr);
+	in_addr.sin6_len = sizeof(in_addr);
 #endif
-	in_addr.sin_family = AF_INET;
-	in_addr.sin_port = htons ((short) XDM_UDP_PORT);
-	if (address->length != 4)
+	in_addr.sin6_family = AF_INET6;
+	in_addr.sin6_flowinfo = 0;
+	in_addr.sin6_port = htons ((short) XDM_UDP_PORT);
+	if (address->length != 16)
 	    return;
-	memmove( (char *) &in_addr.sin_addr, address->data, address->length);
-	addrlen = sizeof (struct sockaddr_in);
+	memmove( (char *) &in_addr.sin6_addr, address->data, address->length);
+	addrlen = sizeof (struct sockaddr_in6);
 	break;
 #endif
 #ifdef AF_DECnet
@@ -287,7 +288,7 @@
 ProcessRequestSocket ()
 {
     XdmcpHeader		header;
-    struct sockaddr_in	addr;
+    struct sockaddr_in6	addr;
     int			addrlen = sizeof addr;
 #ifdef MINIX
     int			r;
@@ -486,7 +487,8 @@
 
 	    data = connectionAddress->data;
 	    hostent = gethostbyaddr ((char *)data,
-				     connectionAddress->length, AF_INET);
+			connectionAddress->length,
+			connectionAddress->length == 4 ? AF_INET : AF_INET6);
 	    if (sourceAddress && hostent) {
 #if defined(__SVR4) && defined(__sun)
 		/*
@@ -548,6 +550,8 @@
 	    {
 		if (!getString (name, 25))
 		    return 0;
+		if (connectionAddress->length != 4)
+		    return 0;
 		if (multiHomed)
 		    data = (CARD8 *) &((struct sockaddr_in *)originalAddress)->
 				sin_addr.s_addr;
@@ -631,6 +635,29 @@
 		}
 		break;
 #endif
+#ifdef AF_INET6
+	    case AF_INET6:
+		{
+		    struct sockaddr_in6	in_addr;
+
+		    if (clientAddress.length != 16 ||
+		        clientPort.length != 2)
+		    {
+			goto badAddress;
+		    }
+		    bzero ((char *) &in_addr, sizeof (in_addr));
+#ifdef BSD44SOCKETS
+		    in_addr.sin6_len = sizeof(in_addr);
+#endif
+		    in_addr.sin6_family = AF_INET6;
+		    in_addr.sin6_flowinfo = 0;
+		    memmove( &in_addr.sin6_addr, clientAddress.data, 16);
+		    memmove( (char *) &in_addr.sin6_port, clientPort.data, 2);
+		    client = (struct sockaddr *) &in_addr;
+		    clientlen = sizeof (in_addr);
+		}
+		break;
+#endif
 #ifdef AF_UNIX
 	    case AF_UNIX:
 		{
@@ -1199,11 +1226,14 @@
 	    char *local_name;
 
 	    hostent = gethostbyaddr ((char *)connectionAddress->data,
-				     connectionAddress->length, AF_INET);
+			connectionAddress->length,
+			connectionAddress->length == 4 ? AF_INET : AF_INET6);
 
 	    if (hostent)
 		local_name = hostent->h_name;
 	    else {
+		if (connectionAddress->length != 4)
+		    break;
 		/* can't get name, so use emergency fallback */
 		sprintf(dotted, "%d.%d.%d.%d",
 			connectionAddress->data[0],
diff -uN X11R6-orig/xc/programs/xdm/access.c X11R6-new/xc/programs/xdm/access.c
--- X11R6-orig/xc/programs/xdm/access.c
+++ X11R6-new/xc/programs/xdm/access.c
@@ -379,6 +379,11 @@
 	    	display->connectionType = FamilyInternet;
 	    	break;
 #endif
+#ifdef AF_INET6
+	    case AF_INET6:
+	    	display->connectionType = FamilyInternet;
+	    	break;
+#endif
 #ifdef AF_DECnet
 	    case AF_DECnet:
 	    	display->connectionType = FamilyDECnet;
diff -uN X11R6-orig/xc/programs/lbxproxy/os/connection.c X11R6-new/xc/programs/lbxproxy/os/connection.c
--- X11R6-orig/xc/programs/lbxproxy/os/connection.c
+++ X11R6-new/xc/programs/lbxproxy/os/connection.c
@@ -230,7 +230,7 @@
 int retry;  /* boolean - retry if addr busy */
 
 {
-    struct sockaddr_in insock;
+    struct sockaddr_in6 insock;
     int request;
     int retryCount;
 #ifndef SO_DONTLINGER
@@ -239,7 +239,7 @@
 #endif /* SO_LINGER */
 #endif /* SO_DONTLINGER */
 
-    if ((request = socket (AF_INET, SOCK_STREAM, 0)) < 0) 
+    if ((request = socket (AF_INET6, SOCK_STREAM, 0)) < 0) 
     {
 	Error ("Creating TCP socket");
 	return -1;
@@ -254,11 +254,12 @@
     {
     bzero ((char *)&insock, sizeof (insock));
 #ifdef BSD44SOCKETS
-    insock.sin_len = sizeof(insock);
+    insock.sin6_len = sizeof(insock);
 #endif
-    insock.sin_family = AF_INET;
-    insock.sin_port = htons ((unsigned short)(X_TCP_PORT + atoi (display)));
-    insock.sin_addr.s_addr = htonl(INADDR_ANY);
+    insock.sin6_family = AF_INET6;
+    insock.sin6_flowinfo = 0;
+    insock.sin6_port = htons ((unsigned short)(X_TCP_PORT + atoi (display)));
+    insock.sin6_addr = in6addr_any;
 
     retryCount = retry ? 19 : 0;
 
@@ -1675,7 +1676,7 @@
 	struct sockaddr_un un;
 #endif /* UNIXCONN */
 #ifdef TCPCONN
-	struct sockaddr_in in;
+	struct sockaddr_in6 in;
 #endif /* TCPCONN */
 #ifdef DNETCONN
 	struct sockaddr_dn dn;
@@ -1700,7 +1701,9 @@
 	fromlen = sizeof (from);
 	if (!getpeername (newconn, &from.sa, &fromlen))
 	{
-	    if (fromlen && (from.sa.sa_family == AF_INET)) 
+	    if (fromlen &&
+		((from.sa.sa_family == AF_INET) ||
+		 (from.sa.sa_family == AF_INET6)))
 	    {
 		int mi = 1;
 		setsockopt (newconn, IPPROTO_TCP, TCP_NODELAY,
diff -uN X11R6-orig/xc/programs/xauth/gethost.c X11R6-new/xc/programs/xauth/gethost.c
--- X11R6-orig/xc/programs/xauth/gethost.c
+++ X11R6-new/xc/programs/xauth/gethost.c
@@ -143,15 +143,21 @@
 	alarm (4);
 	if (setjmp(env) == 0) {
 #endif
-	    hp = gethostbyaddr (auth->address, auth->address_length, AF_INET);
+	    hp = gethostbyaddr (auth->address, auth->address_length,
+			auth->address_length == 4 ? AF_INET : AF_INET6);
 #ifdef SIGALRM
 	}
 	alarm (0);
 #endif
 	if (hp)
 	  return (hp->h_name);
-	else
-	  return (inet_ntoa(*((struct in_addr *)(auth->address))));
+	else {
+	  static char v[64];
+
+	  inet_ntop (auth->address_length == 4 ? AF_INET : AF_INET6,
+		     auth->address, v, sizeof(v));
+	  return (v);
+	}
     }
 #endif
 #ifdef DNETCONN
@@ -171,38 +177,26 @@
 }
 
 #ifdef TCPCONN
-/*
- * cribbed from lib/X/XConnDis.c
- */
 static Bool get_inet_address (name, resultp)
     char *name;
-    unsigned int *resultp;		/* return */
+    struct in6_addr *resultp;		/* return */
 {
-    unsigned int hostinetaddr = inet_addr (name);
     struct hostent *host_ptr;
-    struct sockaddr_in inaddr;		/* dummy variable for size calcs */
 
-#ifndef INADDR_NONE
-#define INADDR_NONE -1
-#endif
-
-    if (hostinetaddr == INADDR_NONE) {
-	if ((host_ptr = gethostbyname (name)) == NULL) {
-	    /* No such host! */
-	    errno = EINVAL;
-	    return False;
-	}
-	/* Check the address type for an internet host. */
-	if (host_ptr->h_addrtype != AF_INET) {
-	    /* Not an Internet host! */
-	    errno = EPROTOTYPE;
-	    return False;
-	}
- 
-	memmove( (char *)&hostinetaddr, (char *)host_ptr->h_addr, 
-	      sizeof(inaddr.sin_addr));
+    if ((host_ptr = gethostbyname (name)) == NULL) {
+	/* No such host! */
+	errno = EINVAL;
+	return False;
     }
-    *resultp = hostinetaddr;
+    /* Check the address type for an internet host. */
+    if (host_ptr->h_addrtype != AF_INET6) {
+	/* Not an Internet host! */
+	errno = EPROTOTYPE;
+	return False;
+    }
+ 
+    memmove( (char *)resultp, (char *)host_ptr->h_addr, 
+	      host_ptr->h_length);
     return True;
 }
 #endif
@@ -238,8 +232,7 @@
     int len = 0;
     char *src = NULL;
 #ifdef TCPCONN
-    unsigned int hostinetaddr;
-    struct sockaddr_in inaddr;		/* dummy variable for size calcs */
+    struct in6_addr hostinetaddr;
 #endif
 #ifdef DNETCONN
     struct dn_naddr dnaddr;
@@ -272,7 +265,7 @@
 #ifdef TCPCONN
 	if (!get_inet_address (host, &hostinetaddr)) return NULL;
 	src = (char *) &hostinetaddr;
-	len = 4; /* sizeof inaddr.sin_addr, would fail on Cray */
+	len = (sizeof hostinetaddr);
 	break;
 #else
 	return NULL;
diff -uN X11R6-orig/xc/programs/xauth/xauth.c X11R6-new/xc/programs/xauth/xauth.c
--- X11R6-orig/xc/programs/xauth/xauth.c
+++ X11R6-new/xc/programs/xauth/xauth.c
@@ -32,6 +32,8 @@
 
 #include "xauth.h"
 
+#include <netinet/in.h>
+#include <resolv.h>
 
 /*
  * global data
@@ -102,6 +104,10 @@
     int status;
 
     ProgramName = argv[0];
+
+    if ((_res.options & RES_INIT) == 0)
+	(void)res_init();
+    _res.options |= RES_USE_INET6;
 
     for (i = 1; i < argc; i++) {
 	char *arg = argv[i];
diff -uN X11R6-orig/xc/programs/Xserver/os/connection.c X11R6-new/xc/programs/Xserver/os/connection.c
--- X11R6-orig/xc/programs/Xserver/os/connection.c
+++ X11R6-new/xc/programs/Xserver/os/connection.c
@@ -46,7 +46,6 @@
 SOFTWARE.
 
 ******************************************************************/
-/* $XFree86: xc/programs/Xserver/os/connection.c,v 3.25.2.2 1997/07/05 15:55:45 dawes Exp $ */
 /*****************************************************************
  *  Stuff to create connections --- OS dependent
  *
@@ -451,6 +450,7 @@
     int auth_id;
 {
     char addr[128];
+    char v[64];
     char *out = addr;
 
     if (!((OsCommPtr)client->osPrivate)->trans_conn) {
@@ -473,6 +473,13 @@
 	    sprintf(out, "IP %s port %d",
 		    inet_ntoa(((struct sockaddr_in *) saddr)->sin_addr),
 		    ntohs(((struct sockaddr_in *) saddr)->sin_port));
+	    break;
+	case AF_INET6:
+	    sprintf(out, "IPv6 %s port %d",
+		    inet_ntop(AF_INET6,
+			      &((struct sockaddr_in6 *) saddr)->sin6_addr,
+			      v, sizeof (v)),
+		    ntohs(((struct sockaddr_in6 *) saddr)->sin6_port));
 	    break;
 #endif
 #ifdef DNETCONN
diff -uN X11R6-orig/xc/programs/Xserver/os/k5auth.c X11R6-new/xc/programs/Xserver/os/k5auth.c
--- X11R6-orig/xc/programs/Xserver/os/k5auth.c
+++ X11R6-new/xc/programs/Xserver/os/k5auth.c
@@ -277,7 +277,7 @@
     long addrlen;
     krb5_error_code retval, retval2;
     register char n;
-    struct sockaddr cli_net_addr;
+    struct sockaddr_in6 cli_net_addr;
     xReq prefix;
     krb5_principal cprinc;
     krb5_data buf;
@@ -299,15 +299,15 @@
     }
     addrlen = sizeof (cli_net_addr);
     if (getpeername(((OsCommPtr)client->osPrivate)->fd,
-		    &cli_net_addr, &addrlen) == -1)
+		    (struct sockaddr *)&cli_net_addr, &addrlen) == -1)
     {
 	if (creds)
 	    krb5_free_creds(creds);
 	return(SendConnSetup(client, "Krb5 stage1: getpeername failed"));
     }
-    if (cli_net_addr.sa_family == AF_UNSPEC
+    if (cli_net_addr.sin6_family == AF_UNSPEC
 #if defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)
-	|| cli_net_addr.sa_family == AF_UNIX
+	|| cli_net_addr.sin6_family == AF_UNIX
 #endif
 	)			/* assume local host */
     {
@@ -324,9 +324,9 @@
     }
     else
     {
-	cli_addr.addrtype = cli_net_addr.sa_family; /* the values
+	cli_addr.addrtype = cli_net_addr.sin6_family; /* the values
 						       are compatible */
-	switch (cli_net_addr.sa_family)
+	switch (cli_net_addr.sin6_family)
 	{
 #ifdef TCPCONN
 	case AF_INET:
@@ -334,6 +334,11 @@
 	    cli_addr.contents =
 		(krb5_octet *)&((struct sockaddr_in *)&cli_net_addr)->sin_addr;
 	    break;
+	case AF_INET6:
+	    cli_addr.length = sizeof (struct in6_addr);
+	    cli_addr.contents =
+		(krb5_octet *)&(&cli_net_addr)->sin6_addr;
+	    break;
 #endif
 #ifdef DNETCONN
 	case AF_DECnet:
@@ -348,7 +353,7 @@
 	    if (creds)
 		krb5_free_creds(creds);
 	    sprintf(kerror, "Krb5 stage1: unknown address family %d from getpeername",
-		    cli_net_addr.sa_family);    
+		    cli_net_addr.sin6_family);    
 	    return(SendConnSetup(client, kerror));
 	}
     }
diff -uN X11R6-orig/xc/programs/Xserver/os/utils.c X11R6-new/xc/programs/Xserver/os/utils.c
--- X11R6-orig/xc/programs/Xserver/os/utils.c
+++ X11R6-new/xc/programs/Xserver/os/utils.c
@@ -1057,7 +1057,9 @@
 
 #if defined(TCPCONN) || defined(STREAMSCONN)
 #ifndef WIN32
+#include <netinet/in.h>
 #include <netdb.h>
+#include <resolv.h>
 #endif
 #endif
 
@@ -1079,6 +1081,10 @@
 	char hname[1024], *hnameptr;
 	struct hostent *host;
 	int len;
+
+	if ((_res.options & RES_INIT) == 0)
+	    (void)res_init();
+	_res.options |= RES_USE_INET6;
 
 	gethostname(hname, 1024);
 	host = gethostbyname(hname);
diff -uN X11R6-orig/xc/programs/Xserver/os/xdmcp.c X11R6-new/xc/programs/Xserver/os/xdmcp.c
--- X11R6-orig/xc/programs/Xserver/os/xdmcp.c
+++ X11R6-new/xc/programs/Xserver/os/xdmcp.c
@@ -38,6 +38,8 @@
 #endif
 #include <netinet/in.h>
 #include <netdb.h>
+#include <resolv.h>
+#undef QUERY
 #else
 #if defined(MINIX)
 #include <net/hton.h>
@@ -76,7 +78,7 @@
 
 static int		    xdmcpSocket, sessionSocket;
 static xdmcp_states	    state;
-static struct sockaddr_in   req_sockaddr;
+static struct sockaddr_in6  req_sockaddr;
 static int		    req_socklen;
 static CARD32		    SessionID;
 static CARD32		    timeOutTime;
@@ -91,7 +93,7 @@
 
 static XdmcpBuffer	    buffer;
 
-static struct sockaddr_in   ManagerAddress;
+static struct sockaddr_in6  ManagerAddress;
 
 static void get_xdmcp_sock(
 #if NeedFunctionPrototypes
@@ -107,7 +109,7 @@
 
 static void recv_willing_msg(
 #if NeedFunctionPrototypes
-    struct sockaddr_in */*from*/,
+    struct sockaddr_in6 */*from*/,
     int /*fromlen*/,
     unsigned /*length*/
 #endif
@@ -327,24 +329,27 @@
 
 #define MAX_BROADCAST	10
 
-static struct sockaddr_in   BroadcastAddresses[MAX_BROADCAST];
+static struct sockaddr_in6  BroadcastAddresses[MAX_BROADCAST];
 static int		    NumBroadcastAddresses;
 
 void
 XdmcpRegisterBroadcastAddress (addr)
     struct sockaddr_in	*addr;
 {
-    struct sockaddr_in	*bcast;
+    struct sockaddr_in6	*bcast;
     if (NumBroadcastAddresses >= MAX_BROADCAST)
 	return;
     bcast = &BroadcastAddresses[NumBroadcastAddresses++];
-    bzero (bcast, sizeof (struct sockaddr_in));
+    bzero (bcast, sizeof (struct sockaddr_in6));
+    /* mapped the IPv4 broadcast address to IPv6 */
 #ifdef BSD44SOCKETS
-    bcast->sin_len = addr->sin_len;
+    bcast->sin6_len = sizeof(struct sockaddr_in6);
 #endif
-    bcast->sin_family = addr->sin_family;
-    bcast->sin_port = htons (xdm_udp_port);
-    bcast->sin_addr = addr->sin_addr;
+    bcast->sin6_family = AF_INET6;
+    bcast->sin6_port = htons (xdm_udp_port);
+    bcast->sin6_flowinfo = 0;
+    bcast->sin6_addr.s6_addr[10] = bcast->sin6_addr.s6_addr[11] = 0xff;
+    memmove(&bcast->sin6_addr.s6_addr[12], &addr->sin_addr, 4);
 }
 
 /*
@@ -745,7 +750,7 @@
 
 /*ARGSUSED*/
 XdmcpAddHost(from, fromlen, AuthenticationName, hostname, status)
-    struct sockaddr_in  *from;
+    struct sockaddr_in6  *from;
     ARRAY8Ptr		AuthenticationName, hostname, status;
 {
     XdmcpSelectHost(from, fromlen, AuthenticationName);
@@ -761,8 +766,8 @@
 static void
 receive_packet()
 {
-    struct sockaddr_in from;
-    int fromlen = sizeof(struct sockaddr_in);
+    struct sockaddr_in6 from;
+    int fromlen = sizeof(struct sockaddr_in6);
     XdmcpHeader	header;
 
     /* read message off socket */
@@ -975,7 +980,7 @@
 #ifndef _MINIX
     int soopts = 1;
 
-    if ((xdmcpSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+    if ((xdmcpSocket = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
 #else /* MINIX */
     char *udp_device;
     int r, s_errno;
@@ -1061,7 +1066,7 @@
 
 	for (i = 0; i < NumBroadcastAddresses; i++)
 	    XdmcpFlush (xdmcpSocket, &buffer, &BroadcastAddresses[i],
-			sizeof (struct sockaddr_in));
+			sizeof (struct sockaddr_in6));
     }
     else
     {
@@ -1072,7 +1077,7 @@
 
 static void
 recv_willing_msg(from, fromlen, length)
-    struct sockaddr_in	*from;
+    struct sockaddr_in6	*from;
     int			fromlen;
     unsigned		length;
 {
@@ -1375,23 +1380,29 @@
 	ErrorF("Xserver: missing host name in command line\n");
 	exit(1);
     }
+
+    if ((_res.options & RES_INIT) == 0)
+	(void)res_init();
+    _res.options |= RES_USE_INET6;
+
     if (!(hep = gethostbyname(argv[i])))
     {
 	ErrorF("Xserver: unknown host: %s\n", argv[i]);
 	exit(1);
     }
 #ifndef _MINIX
-    if (hep->h_length == sizeof (struct in_addr))
+    if (hep->h_length == sizeof (struct in6_addr))
 #else
     if (hep->h_length == sizeof (ipaddr_t))
 #endif
     {
-	memmove(&ManagerAddress.sin_addr, hep->h_addr, hep->h_length);
+	memmove(&ManagerAddress.sin6_addr, hep->h_addr, hep->h_length);
 #ifdef BSD44SOCKETS
-	ManagerAddress.sin_len = sizeof(ManagerAddress);
+	ManagerAddress.sin6_len = sizeof(ManagerAddress);
 #endif
-	ManagerAddress.sin_family = AF_INET;
-	ManagerAddress.sin_port = htons (xdm_udp_port);
+	ManagerAddress.sin6_family = AF_INET6;
+	ManagerAddress.sin6_port = htons (xdm_udp_port);
+	ManagerAddress.sin6_flowinfo = 0;
     }
     else
     {
diff -uN X11R6-orig/xc/programs/Xserver/os/access.c X11R6-new/xc/programs/Xserver/os/access.c
--- X11R6-orig/xc/programs/Xserver/os/access.c
+++ X11R6-new/xc/programs/Xserver/os/access.c
@@ -141,6 +141,7 @@
 #else
 #if !defined(AMOEBA) && !defined(MINIX)
 #include <netdb.h>
+#include <resolv.h>
 #else
 #ifdef AMOEBA
 #include <server/ip/gen/netdb.h>
@@ -583,6 +584,7 @@
     int 		family;
     register HOST 	*host;
     register struct ifreq *ifr;
+    struct in6_addr	mapped;
     
 #ifdef DNETCONN
     struct dn_naddr *dnaddr = getnodeadd();
@@ -641,10 +643,34 @@
         if (family == -1 || family == FamilyLocal)
 	    continue;
 #ifdef DEF_SELF_DEBUG
-	if (family == FamilyInternet) 
-	    ErrorF("Xserver: DefineSelf(): ifname = %s, addr = %d.%d.%d.%d\n",
-		   ifr->ifr_name, addr[0], addr[1], addr[2], addr[3]);
+	if (family == FamilyInternet) {
+	    char v[64];
+
+	    ErrorF("Xserver: DefineSelf(): ifname = %s, addr = %s\n",
+		   ifr->ifr_name,
+		   inet_ntop(len == 4 ? AF_INET : AF_INET6, addr, v, 64));
+	}
 #endif
+	if ((family == FamilyInternet) && (len == 4)) {
+	    /* Mapped IPv4 to IPv6 with special case for loopback */
+	    if (addr[0] == 127 && addr[1] == 0 &&
+		addr[2] == 0 && addr[3] == 1)
+		addr = (unsigned char *)&in6addr_loopback;
+	    else {
+		mapped.s6_addr[0] = mapped.s6_addr[1] = 0;
+		mapped.s6_addr[2] = mapped.s6_addr[3] = 0;
+		mapped.s6_addr[4] = mapped.s6_addr[5] = 0;
+		mapped.s6_addr[6] = mapped.s6_addr[7] = 0;
+		mapped.s6_addr[8] = mapped.s6_addr[9] = 0;
+		mapped.s6_addr[10] = mapped.s6_addr[11] = 0xff;
+		mapped.s6_addr[12] = addr[0];
+		mapped.s6_addr[13] = addr[1];
+		mapped.s6_addr[14] = addr[2];
+		mapped.s6_addr[15] = addr[3];
+	    }
+	    len = sizeof(mapped);
+	    addr = (unsigned char *) &mapped;
+	}
         for (host = selfhosts;
  	     host && !addrEqual (family, addr, len, host);
 	     host = host->next)
@@ -674,9 +700,7 @@
  	     * ignore 'localhost' entries as they're not useful
 	     * on the other end of the wire
 	     */
-	    if (len == 4 &&
-		addr[0] == 127 && addr[1] == 0 &&
-		addr[2] == 0 && addr[3] == 1)
+	    if (acmp(addr, &in6addr_loopback, len))
 		continue;
 
 	    XdmcpRegisterConnection (family, (char *)addr, len);
@@ -743,10 +767,31 @@
     int family;
     pointer addr;
     register HOST *host;
+    struct in6_addr mapped;
 
     family = ConvertAddr(from, &len, (pointer *)&addr);
     if (family == -1 || family == FamilyLocal)
 	return;
+    if ((family == FamilyInternet) && (len == 4)) {
+	/* Mapped IPv4 to IPv6 with special case for loopback */
+	if (((char *)addr)[0] == 127 && ((char *)addr)[1] == 0 &&
+	    ((char *)addr)[2] == 0 && ((char *)addr)[3] == 1)
+	    addr = (pointer)&in6addr_loopback;
+	else {
+	    mapped.s6_addr[0] = mapped.s6_addr[1] = 0;
+	    mapped.s6_addr[2] = mapped.s6_addr[3] = 0;
+	    mapped.s6_addr[4] = mapped.s6_addr[5] = 0;
+	    mapped.s6_addr[6] = mapped.s6_addr[7] = 0;
+	    mapped.s6_addr[8] = mapped.s6_addr[9] = 0;
+	    mapped.s6_addr[10] = mapped.s6_addr[11] = 0xff;
+	    mapped.s6_addr[12] = ((char *)addr)[0];
+	    mapped.s6_addr[13] = ((char *)addr)[1];
+	    mapped.s6_addr[14] = ((char *)addr)[2];
+	    mapped.s6_addr[15] = ((char *)addr)[3];
+	}
+	len = sizeof(mapped);
+	addr = (unsigned char *) &mapped;
+    }
     for (host = selfhosts; host; host = host->next)
     {
 	if (addrEqual(family, addr, len, host))
@@ -788,7 +833,7 @@
     union {
         struct sockaddr	sa;
 #if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
-        struct sockaddr_in in;
+        struct sockaddr_in6 in;
 #endif /* TCPCONN || STREAMSCONN */
 #ifdef DNETCONN
         struct sockaddr_dn dn;
@@ -918,12 +963,16 @@
 #endif /* SECURE_RPC */
 #if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)
 	{
+	    if ((_res.options & RES_INIT) == 0)
+		(void)res_init();
+	    _res.options |= RES_USE_INET6;
+
     	    /* host name */
     	    if (family == FamilyInternet && (hp = gethostbyname (hostname)) ||
 		 (hp = gethostbyname (hostname)))
 	    {
     		saddr.sa.sa_family = hp->h_addrtype;
-		len = sizeof(saddr.sa);
+		len = sizeof(saddr.in);
     		if ((family = ConvertAddr (&saddr.sa, &len, (pointer *)&addr)) != -1)
 		{
 #ifdef h_addr				/* new 4.3bsd version of gethostent */
@@ -1217,11 +1266,7 @@
     {
 #if defined(TCPCONN) || defined(STREAMSCONN) || defined(AMTCPCONN) || defined(MNX_TCPCONN)
       case FamilyInternet:
-#if !defined(AMOEBA)
-	if (length == sizeof (struct in_addr))
-#else
-	if (length == sizeof(ipaddr_t))
-#endif
+	if (length == sizeof (struct in6_addr))
 	    len = length;
 	else
 	    len = -1;
@@ -1252,11 +1297,7 @@
  * Returns 1 if host is invalid, 0 if we've found it. */
 
 InvalidHost (saddr, len)
-#ifndef AMOEBA_ORIG
     register struct sockaddr	*saddr;
-#else
-    register ipaddr_t		*saddr;
-#endif
     int				len;
 {
     int 			family;
@@ -1299,11 +1340,7 @@
 
 static int
 ConvertAddr (saddr, len, addr)
-#ifndef AMOEBA_ORIG
     register struct sockaddr	*saddr;
-#else
-    register ipaddr_t		*saddr;
-#endif
     int				*len;
     pointer			*addr;
 {
@@ -1321,6 +1358,10 @@
     case AF_INET:
         *len = sizeof (struct in_addr);
         *addr = (pointer) &(((struct sockaddr_in *) saddr)->sin_addr);
+        return FamilyInternet;
+    case AF_INET6:
+        *len = sizeof (struct in6_addr);
+        *addr = (pointer) &(((struct sockaddr_in6 *) saddr)->sin6_addr);
         return FamilyInternet;
 #endif
 #ifdef DNETCONN
diff -uN X11R6-orig/xc/programs/xfs/difs/main.c X11R6-new/xc/programs/xfs/difs/main.c
--- X11R6-orig/xc/programs/xfs/difs/main.c
+++ X11R6-new/xc/programs/xfs/difs/main.c
@@ -59,6 +59,10 @@
 #include	"cache.h"
 #include	"site.h"
 
+#include	<sys/types.h>
+#include	<netinet/in.h>
+#include	<resolv.h>
+
 char       *ConnectionInfo;
 int         ConnInfoLen;
 
@@ -93,6 +97,10 @@
 
     argcGlobal = argc;
     argvGlobal = argv;
+
+    if ((_res.options & RES_INIT) == 0)
+	(void)res_init();
+    _res.options |= RES_USE_INET6;
 
     configfilename = DEFAULT_CONFIG_FILE;
 
diff -uN X11R6-orig/xc/programs/xfs/os/access.c X11R6-new/xc/programs/xfs/os/access.c
--- X11R6-orig/xc/programs/xfs/os/access.c
+++ X11R6-new/xc/programs/xfs/os/access.c
@@ -93,7 +93,7 @@
     char        hname[64];
     struct hostent *hp;
 
-    addr->addr_len = sizeof(struct in_addr);
+    addr->addr_len = sizeof(struct in6_addr);
     addr->address = (pointer) fsalloc(addr->addr_len);
     if (!addr->address)
 	return FSBadAlloc;
diff -uN X11R6-orig/xc/programs/xfwp/xfwp.c X11R6-new/xc/programs/xfwp/xfwp.c
--- X11R6-orig/xc/programs/xfwp/xfwp.c
+++ X11R6-new/xc/programs/xfwp/xfwp.c
@@ -57,6 +57,7 @@
 #endif
 #include <sys/wait.h>
 #include <netdb.h>
+#include <resolv.h>
 #include <signal.h>
 #include <errno.h>
 #ifndef Lynx
@@ -157,13 +158,13 @@
 main (int argc, char * argv[])
 {
   struct clientDataStruct 	client_data;	
-  struct sockaddr_in 		dest_server; 
+  struct sockaddr_in6 		dest_server; 
   struct pm_policy 		policy;
   int 				pm_listen_array[MAX_TRANSPORTS];
   int 				pm_conn_counter;
-  struct sockaddr_in		pm_sockaddr_in; 
+  struct sockaddr_in6		pm_sockaddr_in6; 
   int   			rem_listen_counter; 
-  struct sockaddr_in		rem_sockaddr_in;
+  struct sockaddr_in6		rem_sockaddr_in6;
   fd_set 			readable, writable, rinit, winit;
   int				nfds = 0;
   int 				nready = 0;
@@ -190,6 +191,10 @@
   /*
   // now do the rest of the setup
   */
+  if ((_res.options & RES_INIT) == 0)
+    (void) res_init();
+  _res.options |= RES_USE_INET6;
+
   doProcessInputArgs(config_info, argc, argv);
   if ((config_status = doHandleConfigFile(config_info)) == FAILURE)
     exit(1);
@@ -509,7 +514,7 @@
 {
   int			this_server;
   int 			one = 1;
-  struct sockaddr_in 	rem_sockaddr_in;
+  struct sockaddr_in6 	rem_sockaddr_in6;
   int 			port_counter;
   int 			listen_port;
   char			port_buff[10];
@@ -572,7 +577,7 @@
     return FAILURE;
   }
   if ((server_array[this_server]->client_listen_fd = 
-					socket(AF_INET, SOCK_STREAM, 0)) < 0) 
+					socket(AF_INET6, SOCK_STREAM, 0)) < 0) 
   {
 #ifdef DEBUG
       fprintf(stderr,"doRemClientSetup: socket() call failed!");
@@ -593,8 +598,11 @@
   /*
   // set up the rest of the remote client listener
   */
-  bzero((char * ) &rem_sockaddr_in, sizeof(rem_sockaddr_in));
-  rem_sockaddr_in.sin_family = AF_INET;
+  bzero((char * ) &rem_sockaddr_in6, sizeof(rem_sockaddr_in6));
+  rem_sockaddr_in6.sin6_family = AF_INET6;
+  rem_sockaddr_in6.sin6_len = sizeof(rem_sockaddr_in6);
+  rem_sockaddr_in6.sin6_flowinfo = 0;
+  rem_sockaddr_in6.sin6_addr = in6addr_any;
   if (setsockopt(server_array[this_server]->client_listen_fd,
 		 SOL_SOCKET, SO_REUSEADDR,
                  &one, sizeof(one)) < 0) 
@@ -611,10 +619,10 @@
   }
 
   while (True) {
-      rem_sockaddr_in.sin_port = htons(listen_port);
+      rem_sockaddr_in6.sin6_port = htons(listen_port);
       if (bind(server_array[this_server]->client_listen_fd, 
-	       (struct sockaddr *)&rem_sockaddr_in, 
-	       sizeof(rem_sockaddr_in)) == 0)
+	       (struct sockaddr *)&rem_sockaddr_in6, 
+	       sizeof(rem_sockaddr_in6)) == 0)
 	  break;
       if (errno != EADDRINUSE)
       {
@@ -997,7 +1005,7 @@
   int				server_reason_len;
   int 				conn_auth_namelen, conn_auth_datalen;
   char				throw_away[RWBUFFER_SIZE];
-  struct sockaddr_in		server_sockaddr_in;
+  struct sockaddr_in6		server_sockaddr_in6;
   enum CONFIG_CHECK		server_status;
   xConnClientPrefix 		client;    
   xConnSetupPrefix 		prefix;    
@@ -1033,10 +1041,10 @@
     int				check_sock_fd;
     struct timeval		time_val;
     struct timezone		time_zone;
-    struct sockaddr_in		temp_sockaddr_in;
+    struct sockaddr_in6		temp_sockaddr_in6;
     int				retval;
     int				config_check;
-    int				addrlen = sizeof(temp_sockaddr_in);
+    int				addrlen = sizeof(temp_sockaddr_in6);
     /*
     // start by accepting the connection if you can, use pm_listen_array 
     // index to index into ICE listen_object list (this is because the
@@ -1055,17 +1063,17 @@
     // connection; start by using getpeername() to get endpoint info
     */
     retval = getpeername(temp_sock_fd, 
-			 (struct sockaddr*)&temp_sockaddr_in, 
+			 (struct sockaddr*)&temp_sockaddr_in6, 
 			 &addrlen);
 
-    assert(temp_sockaddr_in.sin_family == AF_INET);
+    assert(temp_sockaddr_in6.sin6_family == AF_INET6);
     
     /*
     // then do the configuration check; NOTE:  we're not doing anything
-    // with the server_sockaddr_in argument 
+    // with the server_sockaddr_in6 argument 
     */
-    if ((config_check = doConfigCheck(&temp_sockaddr_in, 
-				      &server_sockaddr_in,
+    if ((config_check = doConfigCheck(&temp_sockaddr_in6, 
+				      &server_sockaddr_in6,
 				      config_info,
 				      PMGR,
 				      &log_data)) == FAILURE)
@@ -1296,17 +1304,18 @@
       // configuration, if connection allowed, allocate
       // the read/write buffer for this connection;
       */
-      struct sockaddr_in  temp_sockaddr_in;
-      int                 temp_sock_fd;
-      int                 temp_sock_len;
-      int                 host_count;
-      int                 config_check;
-      struct timeval	  time_val;
-      struct timezone	  time_zone;
+      struct sockaddr_in6  temp_sockaddr_in6;
+      int                  temp_sock_fd;
+      int                  temp_sock_len;
+      int                  host_count;
+      int                  config_check;
+      struct timeval	   time_val;
+      struct timezone	   time_zone;
+      char		   v1[64], v2[64];
 
-      temp_sock_len = sizeof(temp_sockaddr_in);
+      temp_sock_len = sizeof(temp_sockaddr_in6);
       if ((temp_sock_fd = accept(fd_counter,
-                                 (struct sockaddr *) &temp_sockaddr_in, 
+                                 (struct sockaddr *) &temp_sockaddr_in6, 
 	 			 &temp_sock_len)) < 0)
       {
         /*
@@ -1330,7 +1339,7 @@
       if ((server_status = 
 	doServerConnectSetup(server_array[listen_counter]->x_server_hostport, 
 			     &server_array[listen_counter]->server_fd, 
-			     &server_sockaddr_in)) == FAILURE)
+			     &server_sockaddr_in6)) == FAILURE)
       {
 #ifdef DEBUG
 	fprintf(stderr, 
@@ -1340,7 +1349,7 @@
       }
       if ((server_status = 
 		doServerConnect(&server_array[listen_counter]->server_fd, 
-		&server_sockaddr_in)) == FAILURE)
+		&server_sockaddr_in6)) == FAILURE)
       {
 #ifdef DEBUG
 	fprintf(stderr, 
@@ -1349,15 +1358,18 @@
 	return;
       }
       /*
-      // derive and save the client IP source and destination address strings 
-      // for logging purposes (have to do it here while we have them; even if
-      // this client connection passes the config check, it might fail the
-      // server security checks later); also, init the config_rule_num field
-      */
-      log_data.source = Malloc(strlen(inet_ntoa(temp_sockaddr_in.sin_addr)));
-      log_data.destination = Malloc(strlen(inet_ntoa(server_sockaddr_in.sin_addr)));
-      strcpy(log_data.source, inet_ntoa(temp_sockaddr_in.sin_addr));
-      strcpy(log_data.destination, inet_ntoa(server_sockaddr_in.sin_addr)); 
+      // derive and save the client IPv6 source and destination
+      // address strings for logging purposes (have to do it here
+      // while we have them; even if this client connection passes
+      // the config check, it might fail the server security checks later);
+      // also, init the config_rule_num field
+      */
+      log_data.source = Malloc(strlen(inet_ntop(AF_INET6,
+			    &temp_sockaddr_in6.sin6_addr, v1, sizeof(v1))));
+      log_data.destination = Malloc(strlen(inet_ntop(AF_INET6,
+			    &server_sockaddr_in6.sin6_addr, v2, sizeof(v2))));
+      strcpy(log_data.source, v1);
+      strcpy(log_data.destination, v2);
       log_data.config_rule_num = -1; 
       /*
       // do config check on client source and destination (must do
@@ -1365,8 +1377,8 @@
       // to query and we may not be able to resolve server name 
       // alone from xfindproxy() 
       */
-      if ((config_check = doConfigCheck(&temp_sockaddr_in, 
-				 	&server_sockaddr_in,
+      if ((config_check = doConfigCheck(&temp_sockaddr_in6, 
+				 	&server_sockaddr_in6,
 					config_info,
 					CLIENT,
 				        &log_data)) == FAILURE)
@@ -1448,13 +1460,13 @@
       // server security extension or other loggable events)
       */
       client_conn_array[temp_sock_fd]->source = 
-			Malloc(strlen(inet_ntoa(temp_sockaddr_in.sin_addr)));
+			Malloc(strlen(inet_ntop(AF_INET6,
+			    &temp_sockaddr_in6.sin6_addr, v1, sizeof(v1))));
       client_conn_array[temp_sock_fd]->destination = 
-			Malloc(strlen(inet_ntoa(server_sockaddr_in.sin_addr)));
-      strcpy(client_conn_array[temp_sock_fd]->source, 
-	     inet_ntoa(temp_sockaddr_in.sin_addr));
-      strcpy(client_conn_array[temp_sock_fd]->destination, 
-             inet_ntoa(server_sockaddr_in.sin_addr)); 
+			Malloc(strlen(inet_ntop(AF_INET6,
+			    &server_sockaddr_in6.sin6_addr, v2, sizeof(v2))));
+      strcpy(client_conn_array[temp_sock_fd]->source, v1);
+      strcpy(client_conn_array[temp_sock_fd]->destination, v2);
       /*
       // allocate a buffer for the X server connection 
       // and create the association between client and server 
@@ -1953,7 +1965,7 @@
 	    fprintf(stderr, "Server replied AUTHENTICATE!\n");
 #endif
             /*
-            // retrieve the client IP source and destination address strings 
+            // retrieve the client IPv6 source and destination address strings 
             */
             log_data.source = 
 	       Malloc(strlen
@@ -2024,13 +2036,22 @@
   }/* end if client_conn_array != NULL */
 }
 
-int doConfigCheck(struct sockaddr_in * source_sockaddr_in,
-	          struct sockaddr_in * dest_sockaddr_in,
+#define IN6ADDR_MATCH(x,m,y)	\
+    match = 1; \
+    for (i = 0; i < sizeof(struct in6_addr) && (m).s6_addr[i] != 0; i++) \
+	if (((x).s6_addr[i] & (m).s6_addr[i]) != (y).s6_addr[i]) { \
+	    match = 0; \
+	    break; \
+	}
+
+int doConfigCheck(struct sockaddr_in6 * source_sockaddr_in6,
+	          struct sockaddr_in6 * dest_sockaddr_in6,
 		  struct config * config_info,
 		  int context,
 		  struct log_struct * log_data)
 {
   int			line_counter;
+  int			i, match;
   /*
   // look through the config file parse tree for a source IP address
   // that matches this request
@@ -2039,12 +2060,13 @@
   {
     if (config_info->config_file_data[line_counter] != NULL)
     {
-      if ((source_sockaddr_in->sin_addr.s_addr & 
-	  (~(config_info->config_file_data[line_counter]->source_net))) ==
-	  config_info->config_file_data[line_counter]->source_host)
+      IN6ADDR_MATCH(source_sockaddr_in6->sin6_addr,
+		    config_info->config_file_data[line_counter]->source_net,
+		    config_info->config_file_data[line_counter]->source_host);
+      if (match)
       {
 	/*
-	// okay, the source host and netmask fields pass, see if the
+	// okay, the source host and prefix length fields pass, see if the
         // config file specifies "permit" or "deny" for this host
         */
         if (!strcmp(config_info->config_file_data[line_counter]->permit_deny,
@@ -2059,9 +2081,10 @@
 	    /*
             // compute destination info restrictions
             */
-            if ((dest_sockaddr_in->sin_addr.s_addr & 
-	        (~(config_info->config_file_data[line_counter]->dest_net))) ==
-	        config_info->config_file_data[line_counter]->dest_host)
+	    IN6ADDR_MATCH(dest_sockaddr_in6->sin6_addr,
+		config_info->config_file_data[line_counter]->dest_net,
+		config_info->config_file_data[line_counter]->dest_host);
+            if (match)
 	    {
 	      /*
 	      // you got a match on the destination, so look at 
@@ -2165,9 +2188,10 @@
 	    /*
             // compute destination info restrictions
             */
-            if ((dest_sockaddr_in->sin_addr.s_addr & 
-	        (~(config_info->config_file_data[line_counter]->dest_net))) ==
-	        config_info->config_file_data[line_counter]->dest_host)
+	    IN6ADDR_MATCH(dest_sockaddr_in6->sin6_addr,
+		config_info->config_file_data[line_counter]->dest_net,
+		config_info->config_file_data[line_counter]->dest_host);
+            if (match)
 	    {
 	      /*
 	      // you got a match on the destination, so look at
@@ -2286,7 +2310,7 @@
   if (config_info->config_file_path == NULL)
   {
     if (printConfigVerify)
-	fputs("matched default permit 0.0.0.0 255.255.255.255\n", stderr);
+	fputs("matched default permit :: 0\n", stderr);
     /*
     // there's no rule match to save
     */
@@ -2295,7 +2319,7 @@
   }
 
   if (printConfigVerify)
-      fputs("matched default deny 0.0.0.0 255.255.255.255\n", stderr);
+      fputs("matched default deny :: 0\n", stderr);
   /*
   // not in this case either 
   */
@@ -2389,8 +2413,8 @@
       pmGetProxyAddrReplyMsg *	pReply;
       char *			pReplyData;
       struct hostent * 		hostptr;
-      struct sockaddr_in	server_sockaddr_in;
-      struct sockaddr_in	dummy_sockaddr_in;
+      struct sockaddr_in6	server_sockaddr_in6;
+      struct sockaddr_in6	dummy_sockaddr_in6;
       char *			server_name_base;
       int			config_check;
       char *			config_failure = "unrecognized server or permission denied";
@@ -2491,9 +2515,9 @@
 #endif
 	goto sendFailure;
       }
-      memset(&server_sockaddr_in, 0, sizeof(server_sockaddr_in));
-      memset(&dummy_sockaddr_in, 0, sizeof(dummy_sockaddr_in)); 
-      memcpy((char *) &server_sockaddr_in.sin_addr, 
+      memset(&server_sockaddr_in6, 0, sizeof(server_sockaddr_in6));
+      memset(&dummy_sockaddr_in6, 0, sizeof(dummy_sockaddr_in6)); 
+      memcpy((char *) &server_sockaddr_in6.sin6_addr, 
 	 hostptr->h_addr,
 	 hostptr->h_length);
 
@@ -2503,11 +2527,11 @@
       // NOTE:  source configuration will always match (see XFWP man
       // page) unless sysadmin explicitly chooses to deny 
       */
-      memcpy((char *) &dummy_sockaddr_in.sin_addr, 
+      memcpy((char *) &dummy_sockaddr_in6.sin6_addr, 
 	 hostptr->h_addr,
 	 hostptr->h_length);
-      if ((config_check = doConfigCheck(&dummy_sockaddr_in, 
-  				        &server_sockaddr_in,
+      if ((config_check = doConfigCheck(&dummy_sockaddr_in6, 
+  				        &server_sockaddr_in6,
 				        global_data.config_info,
 				        FINDPROXY,
 					&log_data)) == FAILURE)
@@ -2753,7 +2777,7 @@
 
 int doServerConnectSetup(char * x_server_hostport,
                          int * server_connect_fd,
-                         struct sockaddr_in * server_sockaddr_in)
+                         struct sockaddr_in6 * server_sockaddr_in6)
 {
   struct hostent * 	hostptr;
   char *		server_name_base;
@@ -2790,7 +2814,7 @@
 #endif
     return;
   }
-  if ((*server_connect_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+  if ((*server_connect_fd = socket(AF_INET6, SOCK_STREAM, 0)) < 0)
   {
 #ifdef DEBUG
     fprintf(stderr, 
@@ -2799,20 +2823,21 @@
 #endif
     return FAILURE;
   }
-  memset(server_sockaddr_in, 0, sizeof(*server_sockaddr_in));
-  server_sockaddr_in->sin_family = hostptr->h_addrtype;
-  memcpy((char *) &server_sockaddr_in->sin_addr, 
+  memset(server_sockaddr_in6, 0, sizeof(*server_sockaddr_in6));
+  server_sockaddr_in6->sin6_family = hostptr->h_addrtype;
+  server_sockaddr_in6->sin6_len = sizeof(*server_sockaddr_in6);
+  memcpy((char *) &server_sockaddr_in6->sin6_addr, 
 	 hostptr->h_addr,
 	 hostptr->h_length);
-  server_sockaddr_in->sin_port = htons(server_port);
+  server_sockaddr_in6->sin6_port = htons(server_port);
   return SUCCESS;
 }
 
 int doServerConnect(int * server_connect_fd,
-                    struct sockaddr_in * server_sockaddr_in)
+                    struct sockaddr_in6 * server_sockaddr_in6)
 {
-  if(connect(*server_connect_fd, (struct sockaddr * )server_sockaddr_in,
-	     sizeof(*server_sockaddr_in)) < 0)
+  if(connect(*server_connect_fd, (struct sockaddr * )server_sockaddr_in6,
+	     sizeof(*server_sockaddr_in6)) < 0)
   {
 #ifdef DEBUG
     fprintf(stderr, 
@@ -3116,13 +3141,13 @@
 
   config_lineP->permit_deny = NULL;
   config_lineP->source_hostname = NULL;
-  config_lineP->source_host = 0;
-  config_lineP->source_netmask = NULL;
-  config_lineP->source_net = 0;
+  bzero((char *)&config_lineP->source_host, sizeof(struct in6_addr));
+  config_lineP->source_preflen = NULL;
+  bzero((char *)&config_lineP->source_net, sizeof(struct in6_addr));
   config_lineP->dest_hostname = NULL;
-  config_lineP->dest_host = 0;
-  config_lineP->dest_netmask = NULL;
-  config_lineP->dest_net = 0;
+  bzero((char *)&config_lineP->dest_host, sizeof(struct in6_addr));
+  config_lineP->dest_preflen = NULL;
+  bzero((char *)&config_lineP->dest_net, sizeof(struct in6_addr));
   config_lineP->operator = NULL;
   config_lineP->service = NULL; 
 
@@ -3194,7 +3219,7 @@
   {
     char   	token[64];
     strcpy(token, result);
-    if (doVerifyHostMaskToken(token))
+    if (doVerifyHostToken(token))
     {
       if ((config_file_data[line_number]->source_hostname = 
 				      (char *) malloc (strlen(result) + 1)) == NULL)
@@ -3213,22 +3238,24 @@
       /*
       // generate network address format
       */
-      config_file_data[line_number]->source_host = 
-	      inet_addr(config_file_data[line_number]->source_hostname);
+      inet_pton(AF_INET6,
+		config_file_data[line_number]->source_hostname,
+		&config_file_data[line_number]->source_host);
     } else
       bad_token = 1;
   }
 
   /*
-  // now the source netmask field
+  // now the source prefix length field
   */
   if ((result = strtok(NULL, SEPARATOR1)) != NULL)
   {
     char   	token[64];
+    int		plen, j;
     strcpy(token, result);
-    if (doVerifyHostMaskToken(token))
+    if (doVerifyMaskToken(token))
     {
-      if ((config_file_data[line_number]->source_netmask = 
+      if ((config_file_data[line_number]->source_preflen = 
 				      (char *) malloc (strlen(result) + 1)) == NULL)
       {
 #ifdef DEBUG
@@ -3236,14 +3263,18 @@
 #endif
 	return 0;
       }
-      strcpy(config_file_data[line_number]->source_netmask, result);
+      strcpy(config_file_data[line_number]->source_preflen, result);
 #ifdef DEBUG
       fprintf(stderr, 
 	   "third token = %s\n", 
-	    config_file_data[line_number]->source_netmask);
+	    config_file_data[line_number]->source_preflen);
 #endif
-      config_file_data[line_number]->source_net = 
-	      inet_addr(config_file_data[line_number]->source_netmask);
+      plen = atoi(config_file_data[line_number]->source_preflen);
+      for (j = 0; plen >= 8; plen -= 8, j++)
+	config_file_data[line_number]->source_net.s6_addr[j] = 0xff;
+      if (plen != 0)
+	config_file_data[line_number]->source_net.s6_addr[j] =
+	    0xff << (8 - plen);
     } else
       bad_token = 1;
   }
@@ -3254,7 +3285,7 @@
   {
     char   	token[64];
     strcpy(token, result);
-    if (doVerifyHostMaskToken(token))
+    if (doVerifyHostToken(token))
     {
       if ((config_file_data[line_number]->dest_hostname = 
 				      (char *) malloc (strlen(result) + 1)) == NULL)
@@ -3270,21 +3301,23 @@
 	   "fourth token = %s\n", 
 	    config_file_data[line_number]->dest_hostname);
 #endif
-      config_file_data[line_number]->dest_host = 
-	      inet_addr(config_file_data[line_number]->dest_hostname);
+      inet_pton(AF_INET6,
+		config_file_data[line_number]->dest_hostname,
+		&config_file_data[line_number]->dest_host);
     } else
       bad_token = 1;
   }
   /*
-  // now the destination netmask field
+  // now the destination prefix length field
   */
   if ((result = strtok(NULL, SEPARATOR1)) != NULL)
   {
     char   	token[64];
+    int		plen, j;
     strcpy(token, result);
-    if (doVerifyHostMaskToken(token))
+    if (doVerifyMaskToken(token))
     {
-      if ((config_file_data[line_number]->dest_netmask = 
+      if ((config_file_data[line_number]->dest_preflen = 
 				      (char *) malloc (strlen(result) + 1)) == NULL)
       {
 #ifdef DEBUG
@@ -3292,14 +3325,18 @@
 #endif
 	return 0;
       }
-      strcpy(config_file_data[line_number]->dest_netmask, result);
+      strcpy(config_file_data[line_number]->dest_preflen, result);
 #ifdef DEBUG
       fprintf(stderr, 
 	   "fifth token = %s\n", 
-	    config_file_data[line_number]->dest_netmask);
+	    config_file_data[line_number]->dest_preflen);
 #endif
-      config_file_data[line_number]->dest_net = 
-	      inet_addr(config_file_data[line_number]->dest_netmask);
+      plen = atoi(config_file_data[line_number]->dest_preflen);
+      for (j = 0; plen >= 8; plen -= 8, j++)
+	config_file_data[line_number]->dest_net.s6_addr[j] = 0xff;
+      if (plen != 0)
+	config_file_data[line_number]->dest_net.s6_addr[j] =
+	    0xff << (8 - plen);
     } else
       bad_token = 1;
   }
@@ -3371,9 +3408,9 @@
       ((config_file_data[line_number]->permit_deny != NULL) && 
        (config_file_data[line_number]->source_hostname == NULL)) ||
       ((config_file_data[line_number]->source_hostname != NULL) && 
-       (config_file_data[line_number]->source_netmask == NULL)) || 
+       (config_file_data[line_number]->source_preflen == NULL)) || 
       ((config_file_data[line_number]->dest_hostname != NULL) && 
-       (config_file_data[line_number]->dest_netmask == NULL)) || 
+       (config_file_data[line_number]->dest_preflen == NULL)) || 
       ((config_file_data[line_number]->operator != NULL) && 
        (config_file_data[line_number]->service == NULL)))
       return 1;
@@ -3382,27 +3419,23 @@
   return 0;
 }
 
-int doVerifyHostMaskToken(char token[])
+int doVerifyHostToken(char token[])
 {
-  char * result;
-  int	 delimiter_count = 0;
+  struct in6_addr addr;
   /*
-  // verify there are 3 "." delimiters in the token
+  // verify it is a real IPv6 address
   */
-  while (token)
-  {
-    if ((result = strchr(token, SEPARATOR2)) != NULL)
-    {
-      token = result;
-      delimiter_count++;
-      token ++;
-    } else
-      token = result;
-  }
-  if ((delimiter_count < 3) || (delimiter_count > 3))
-    return 0; 
-  else
-    return 1;
+  return (inet_pton(AF_INET6, token, &addr) > 0);
+}
+
+int doVerifyMaskToken(char token[])
+{
+  int plen;
+  /*
+  // verify it is a legal prefix length
+  */
+  plen = atoi(token);
+  return ((plen >= 0) && (plen <= 128));
 }
 
 void BadSyntax(char *msg, int line)
@@ -3477,8 +3510,8 @@
   struct config_line *ruleP = config_info->config_file_data[line_counter];
   fprintf(stderr,"matched: %s %s %s %s %s %s %s\n",
 	  ruleP->permit_deny,
-	  ruleP->source_hostname, ruleP->source_netmask,
-	  ruleP->dest_hostname, ruleP->dest_netmask,
+	  ruleP->source_hostname, ruleP->source_preflen,
+	  ruleP->dest_hostname, ruleP->dest_preflen,
 	  ruleP->operator,
 	  ruleP->service);
 }
diff -uN X11R6-orig/xc/programs/xfwp/xfwp.h X11R6-new/xc/programs/xfwp/xfwp.h
--- X11R6-orig/xc/programs/xfwp/xfwp.h
+++ X11R6-new/xc/programs/xfwp/xfwp.h
@@ -61,7 +61,7 @@
 /* allocate ADD_LINES entries at a time when loading the configuration */
 #define ADD_LINES		20
 #define SEPARATOR1              " \t\n"
-#define SEPARATOR2              '.'
+#define SEPARATOR2              ':'
 
 #define		min(a,b)		((a) < (b) ? (a) : (b))
 #define		max(a,b)		((a) > (b) ? (a) : (b))
@@ -194,13 +194,13 @@
 {
   char * 		permit_deny;
   char * 		source_hostname;
-  unsigned int		source_host;
-  char * 		source_netmask;
-  unsigned int  	source_net;
+  struct in6_addr	source_host;
+  char * 		source_preflen;
+  struct in6_addr  	source_net;
   char * 		dest_hostname;
-  unsigned int 	 	dest_host;
-  char * 		dest_netmask;
-  unsigned int	 	dest_net;
+  struct in6_addr 	dest_host;
+  char * 		dest_preflen;
+  struct in6_addr 	dest_net;
   char * 		operator;
   char * 		service;
   int	 		service_id;
@@ -303,8 +303,8 @@
                       struct client_conn_buf * client_conn_array[],
                       struct ice_data * ice_data);
 
-int doConfigCheck(struct sockaddr_in * temp_sockaddr_in,
-		  struct sockaddr_in * server_sockaddr_in,
+int doConfigCheck(struct sockaddr_in6 * temp_sockaddr_in6,
+		  struct sockaddr_in6 * server_sockaddr_in6,
                   struct config * config_info,
 		  int context,
 		  struct log_struct * log_data);
@@ -337,10 +337,10 @@
 
 int doServerConnectSetup(char * x_server_hostport, 
 			 int * server_connect_fd, 
-			 struct sockaddr_in * server_addr_in);
+			 struct sockaddr_in6 * server_addr_in6);
 
 int doServerConnect(int * server_connect_fd, 
-		    struct sockaddr_in * server_addr_in);
+		    struct sockaddr_in6 * server_addr_in6);
 
 int doProcessLine(char *line,
                    struct config * config_info,
@@ -352,7 +352,9 @@
 
 Bool doConfigRequireDisallow(int, char*);
 
-int doVerifyHostMaskToken(char token[]);
+int doVerifyHostToken(char token[]);
+
+int doVerifyMaskToken(char token[]);
 
 void doInstallIOErrorHandler();
 
diff -uN X11R6-orig/xc/programs/xfwp/xfwp.man X11R6-new/xc/programs/xfwp/xfwp.man
--- X11R6-orig/xc/programs/xfwp/xfwp.man
+++ X11R6-new/xc/programs/xfwp/xfwp.man
@@ -206,7 +206,7 @@
 packet-filtering routers.  It contains zero or more source-destination
 rules of the following form:
 .PP
-[#]{permit | deny} <src> <src mask> [<dest> <dest mask> [<operator> <service>]]
+[#]{permit | deny} <src> <src len> [<dest> <dest len> [<operator> <service>]]
 .sp
 .IP # 12
 comment delimiter; evaluator will skip these lines 
@@ -214,21 +214,21 @@
 the keywords ``permit'' or ``deny'' indicate whether the 
 rule will enable or disable access, respectively
 .IP src 12
-the IP address against the host who originated the 
-connection request will be matched, expressed in IP 
-format (x.x.x.x)
-.IP "src mask" 12
-a subnet mask, also in IP format, for further qualifying
-the source mask.  Bits set in the mask indicate bits of the
+the IPv6 address against the host who originated the 
+connection request will be matched, expressed in IPv6
+format (x:x:x:x:x:x:x:x)
+.IP "src len" 12
+a prefix length, a number between 0 and 128, for further qualifying
+the source prefix.  Bits after the prefix indicate bits of the
 incoming address to be \fIignored\fP when comparing to the specified src
 .IP dest 12
-the IP address against which the destination of the 
-incoming connection request (i.e. the host IP of the 
+the IPv6 address against which the destination of the 
+incoming connection request (i.e. the host IPv6 of the 
 X server to which the incoming client is attempting to
 connect) will be matched
-.IP "dest mask" 12
-a subnet mask, also in IP format, for further qualifying
-the destination mask.  Bits set in the mask indicate bits of the
+.IP "dest len" 12
+a prefix length, a number between 0 and 128, for further qualifying
+the destination prefix.  Bits after the prefix indicate bits of the
 destination address to be \fIignored\fP when comparing to the specified dest
 .IP operator 12
 always ``eq'' (if the service field is not NULL)
@@ -267,8 +267,8 @@
 .RS 3
   while (more entries to check)
   {
-    if ((<originator IP> AND (NOT <src mask>)) == src)
-      [if ((<dest X server IP> AND (NOT <dest mask>)) == dest)] 
+    if ((<originator IPv6> AND (<src prefix>)) == src)
+      [if ((<dest X server IPv6> AND (<dest prefix>)) == dest)] 
         [if (service fields present and matching)]
           do either permit or deny connection depending on keyword
     else
@@ -312,22 +312,22 @@
 require policy1
 require policy2
 #
-# deny pm connections originating on 8.7.6.5 [NOTE:  If pm service
+# deny pm connections originating on 8:7:6:5:4:3:2:1 [NOTE:  If pm service
 # is explicitly qualified, line must include destination fields as
 # shown.]
 #
-deny  8.7.6.5  0.0.0.0  0.0.0.0  255.255.255.255  eq  pm
+deny  8:7:6:5:4:3:2:1  128  ::  0  eq  pm
 #
 # permit xfindproxy X server connects to anywhere [NOTE:  If
 # fp service is explicitly qualified, line must include source fields
 # as shown.]
 #
-permit  0.0.0.0  255.255.255.255   0.0.0.0  255.255.255.255  eq  fp 
+permit  ::  0   ::  0  eq  fp 
 #
-# permit all connection types originating from the 192.0.0.0 
-# IP domain only 
+# permit all connection types originating from the fec0::/10
+# IPv6 domain only 
 #
-permit  192.0.0.0   0.255.255.255 
+permit  fec0::   10
 .fi
 \fP
 .PP
diff -uN X11R6-orig/xc/programs/xhost/xhost.c X11R6-new/xc/programs/xhost/xhost.c
--- X11R6-orig/xc/programs/xhost/xhost.c
+++ X11R6-new/xc/programs/xhost/xhost.c
@@ -75,6 +75,7 @@
 #endif
 #include <netdb.h>
 #include <netinet/in.h>
+#include <resolv.h>
 #else
 #include <server/ip/gen/socket.h>
 #include <server/ip/types.h>
@@ -153,6 +154,9 @@
 #ifdef	AF_INET
         { AF_INET, FamilyInternet },
 #endif
+#ifdef	AF_INET6
+        { AF_INET6, FamilyInternet },
+#endif
 };
 
 #define FAMILIES ((sizeof familyMap)/(sizeof familyMap[0]))
@@ -184,6 +188,12 @@
  
     ProgramName = argv[0];
 
+#ifdef NEEDSOCKETS
+    if ((_res.options & RES_INIT) == 0)
+	(void)res_init();
+    _res.options |= RES_USE_INET6;
+#endif
+
     if ((dpy = XOpenDisplay(NULL)) == NULL) {
 	fprintf(stderr, "%s:  unable to open display \"%s\"\n",
 		ProgramName, XDisplayName (NULL));
@@ -308,7 +318,7 @@
 #endif
 #ifdef NEEDSOCKETS
 #ifndef AMTCPCONN
-    static struct in_addr addr;	/* so we can point at it */
+    static struct in6_addr addr;	/* so we can point at it */
 #else
     static ipaddr_t addr;
 #endif
@@ -484,41 +494,30 @@
     }
 #ifdef NEEDSOCKETS
     /*
-     * First see if inet_addr() can grok the name; if so, then use it.
-     */
-#ifndef AMTCPCONN
-    if ((addr.s_addr = inet_addr(name)) != -1) {
-#else
-    if ((addr = inet_addr(name)) != -1) {
-#endif
-	ha.family = FamilyInternet;
-	ha.length = 4;		/* but for Cray would be sizeof(addr.s_addr) */
-	ha.address = (char *)&addr; /* but for Cray would be &addr.s_addr */
-	if (add) {
-	    XAddHost (dpy, &ha);
-	    printf ("%s %s\n", name, add_msg);
-	} else {
-	    XRemoveHost (dpy, &ha);
-	    printf ("%s %s\n", name, remove_msg);
-	}
-	return 1;
-    } 
-    /*
+     * (gethostbyname knows how to handle litterals...)
      * Is it in the namespace?
      */
-    else if (((hp = gethostbyname(name)) == (struct hostent *)NULL)
-	     || hp->h_addrtype != AF_INET) {
+    if (((hp = gethostbyname(name)) == (struct hostent *)NULL)
+	     || hp->h_addrtype != AF_INET6) {
 	return 0;
     } else {
 	ha.family = XFamily(hp->h_addrtype);
-	ha.length = hp->h_length;
 #ifdef h_addr			/* new 4.3bsd version of gethostent */
     {
 	char **list;
 
 	/* iterate over the hosts */
 	for (list = hp->h_addr_list; *list; list++) {
+	    ha.length = hp->h_length;
 	    ha.address = *list;
+#ifdef UNMAPPED_IPV4
+	    if ((ha.family == FamilyInternet) &&
+		(ha.length == sizeof(struct in6_addr)) &&
+		IN6_IS_ADDR_V4MAPPED((struct in6_addr *)ha.address)) {
+		ha.length = sizeof(struct in_addr);
+		ha.address += sizeof(struct in6_addr) - sizeof(struct in_addr);
+	    }
+#endif
 	    if (add) {
 		XAddHost (dpy, &ha);
 	    } else {
@@ -527,7 +526,16 @@
 	}
     }
 #else
+	ha.length = hp->h_length;
 	ha.address = hp->h_addr;
+#ifdef UNMAPPED_IPV4
+	if ((ha.family == FamilyInternet) &&
+	    (ha.length == sizeof(struct in6_addr)) &&
+	    IN6_IS_ADDR_V4MAPPED((struct in6_addr *)ha.address)) {
+	    ha.length = sizeof(struct in_addr);
+	    ha.address += sizeof(struct in6_addr) - sizeof(struct in_addr);
+	}
+#endif
 	if (add) {
 	    XAddHost (dpy, &ha);
 	} else {
@@ -545,7 +553,7 @@
 
 /*
  * get_hostname - Given an internet address, return a name (CHARON.MIT.EDU)
- * or a string representing the address (18.58.0.13) if the name cannot
+ * or a string representing the address (::ffff:18.58.0.13) if the name cannot
  * be found.
  */
 
@@ -556,7 +564,7 @@
 {
 #if defined(TCPCONN) || defined(STREAMSCONN) || defined(AMTCPCONN)
     struct hostent *hp = NULL;
-    char *inet_ntoa();
+    static char v[64];
 #endif
 #ifdef DNETCONN
     struct nodeent *np;
@@ -571,12 +579,6 @@
 
 #if defined(TCPCONN) || defined(STREAMSCONN) || defined(AMTCPCONN)
     if (ha->family == FamilyInternet) {
-#ifdef CRAY
-	struct in_addr t_addr;
-	bzero((char *)&t_addr, sizeof(t_addr));
-	bcopy(ha->address, (char *)&t_addr, 4);
-	ha->address = (char *)&t_addr;
-#endif
 	/* gethostbyaddr can take a LONG time if the host does not exist.
 	   Assume that if it does not respond in NAMESERVER_TIMEOUT seconds
 	   that something is wrong and do not make the user wait.
@@ -586,16 +588,17 @@
 	signal(SIGALRM, nameserver_lost);
 	alarm(4);
 	if (setjmp(env) == 0) {
-	    hp = gethostbyaddr (ha->address, ha->length, AF_INET);
+	    hp = gethostbyaddr (ha->address, ha->length,
+				ha->length == 4 ? AF_INET : AF_INET6);
 	}
 	alarm(0);
 	if (hp)
 	    return (hp->h_name);
-#ifndef AMTCPCONN
-	else return (inet_ntoa(*((struct in_addr *)(ha->address))));
-#else
-	else return (inet_ntoa(*((ipaddr_t *)(ha->address))));
-#endif
+	else {
+	    inet_ntop(ha->length == 4 ? AF_INET : AF_INET6,
+		      ha->address, v, sizeof(v));
+	    return (v);
+	}
     }
 #endif
     if (ha->family == FamilyNetname) {
