The path below will fix the problem that arises when running 
a client on an inet4 only system over tcp with Xlib compiled 
with inet6 support. 

If noone objects I'll commit it.

Egbert.

Index: Xtranssock.c
===================================================================
RCS file: /home/eich/cvs/xc/lib/xtrans/Xtranssock.c,v
retrieving revision 1.1.1.10
diff -u -r1.1.1.10 Xtranssock.c
--- Xtranssock.c        6 Aug 2003 16:17:24 -0000       1.1.1.10
+++ Xtranssock.c        7 Aug 2003 13:12:47 -0000
@@ -192,6 +192,7 @@
     {"tcp",AF_INET,SOCK_STREAM,SOCK_DGRAM,0},
 #else /* IPv6 */
     {"tcp",AF_INET6,SOCK_STREAM,SOCK_DGRAM,0},
+    {"tcp",AF_INET,SOCK_STREAM,SOCK_DGRAM,0}, /* fallback */
     {"inet6",AF_INET6,SOCK_STREAM,SOCK_DGRAM,0},
 #endif
 #endif /* TCPCONN */
@@ -275,20 +276,20 @@
  */
 
 static int
-TRANS(SocketSelectFamily) (char *family)
+TRANS(SocketSelectFamily) (int first, char *family)
 
 {
     int     i;
 
     PRMSG (3,"SocketSelectFamily(%s)\n", family, 0, 0);
 
-    for (i = 0; i < NUMSOCKETFAMILIES;i++)
+    for (i = first + 1; i < NUMSOCKETFAMILIES;i++)
     {
         if (!strcmp (family, Sockettrans2devtab[i].transname))
            return i;
     }
 
-    return -1;
+    return (first == -1 ? -2 : -1);
 }
 
 
@@ -418,7 +419,7 @@
 #endif
 #endif
       ) {
-       PRMSG (1, "SocketOpen: socket() failed for %s\n",
+       PRMSG (2, "SocketOpen: socket() failed for %s\n",
            Sockettrans2devtab[i].transname, 0, 0);
 
        xfree ((char *) ciptr);
@@ -483,26 +484,25 @@
 
 {
     XtransConnInfo     ciptr;
-    int                        i;
+    int                        i = -1;
 
     PRMSG (2, "SocketOpenCOTSClient(%s,%s,%s)\n",
        protocol, host, port);
 
     SocketInitOnce();
 
-    if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0)
-    {
-       PRMSG (1,
-       "SocketOpenCOTSClient: Unable to determine socket type for %s\n",
-           thistrans->TransName, 0, 0);
-       return NULL;
-    }
-
-    if ((ciptr = TRANS(SocketOpen) (
-       i, Sockettrans2devtab[i].devcotsname)) == NULL)
-    {
-       PRMSG (1,"SocketOpenCOTSClient: Unable to open socket for %s\n",
-           thistrans->TransName, 0, 0);
+    while ((i = TRANS(SocketSelectFamily) (i, thistrans->TransName)) >= 0) {
+       if ((ciptr = TRANS(SocketOpen) (
+                i, Sockettrans2devtab[i].devcotsname)) != NULL)
+           break;
+    }
+    if (i < 0) {
+       if (i == -1)
+           PRMSG (1,"SocketOpenCOTSClient: Unable to open socket for %s\n",
+                  thistrans->TransName, 0, 0);
+       else
+           PRMSG (1,"SocketOpenCOTSClient: Unable to determine socket type for %s\n",
+                  thistrans->TransName, 0, 0);
        return NULL;
     }
 
@@ -524,25 +524,24 @@
 
 {
     XtransConnInfo     ciptr;
-    int        i;
+    int        i = -1;
 
     PRMSG (2,"SocketOpenCOTSServer(%s,%s,%s)\n", protocol, host, port);
 
     SocketInitOnce();
 
-    if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0)
-    {
-       PRMSG (1,
-       "SocketOpenCOTSServer: Unable to determine socket type for %s\n",
-           thistrans->TransName, 0, 0);
-       return NULL;
-    }
-
-    if ((ciptr = TRANS(SocketOpen) (
-       i, Sockettrans2devtab[i].devcotsname)) == NULL)
-    {
-       PRMSG (1,"SocketOpenCOTSServer: Unable to open socket for %s\n",
-           thistrans->TransName, 0, 0);
+    while ((i = TRANS(SocketSelectFamily) (i, thistrans->TransName)) >= 0) {
+       if ((ciptr = TRANS(SocketOpen) (
+                i, Sockettrans2devtab[i].devcotsname)) != NULL)
+           break;
+    }
+    if (i < 0) {
+       if (i == -1)
+           PRMSG (1,"SocketOpenCOTSServer: Unable to open socket for %s\n",
+                  thistrans->TransName, 0, 0);
+       else
+           PRMSG (1,"SocketOpenCOTSServer: Unable to determine socket type for %s\n",
+                  thistrans->TransName, 0, 0);
        return NULL;
     }
 
@@ -592,25 +591,24 @@
 
 {
     XtransConnInfo     ciptr;
-    int                        i;
+    int                        i = -1;
 
     PRMSG (2,"SocketOpenCLTSClient(%s,%s,%s)\n", protocol, host, port);
 
     SocketInitOnce();
 
-    if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0)
-    {
-       PRMSG (1,
-       "SocketOpenCLTSClient: Unable to determine socket type for %s\n",
-           thistrans->TransName, 0, 0);
-       return NULL;
-    }
-
-    if ((ciptr = TRANS(SocketOpen) (
-       i, Sockettrans2devtab[i].devcotsname)) == NULL)
-    {
-       PRMSG (1,"SocketOpenCLTSClient: Unable to open socket for %s\n",
-             thistrans->TransName, 0, 0);
+    while ((i = TRANS(SocketSelectFamily) (i, thistrans->TransName)) >= 0) {
+       if ((ciptr = TRANS(SocketOpen) (
+                i, Sockettrans2devtab[i].devcotsname)) != NULL)
+           break;
+    }
+    if (i < 0) {
+       if (i == -1)
+           PRMSG (1,"SocketOpenCLTSClient: Unable to open socket for %s\n",
+                  thistrans->TransName, 0, 0);
+       else
+           PRMSG (1,"SocketOpenCLTSClient: Unable to determine socket type for %s\n",
+                  thistrans->TransName, 0, 0);
        return NULL;
     }
 
@@ -632,27 +630,27 @@
 
 {
     XtransConnInfo     ciptr;
-    int        i;
+    int        i = -1;
 
     PRMSG (2,"SocketOpenCLTSServer(%s,%s,%s)\n", protocol, host, port);
 
     SocketInitOnce();
 
-    if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0)
-    {
-       PRMSG (1,
-       "SocketOpenCLTSServer: Unable to determine socket type for %s\n",
-             thistrans->TransName, 0, 0);
+    while ((i = TRANS(SocketSelectFamily) (i, thistrans->TransName)) >= 0) {
+       if ((ciptr = TRANS(SocketOpen) (
+                i, Sockettrans2devtab[i].devcotsname)) != NULL)
+           break;
+    }
+    if (i < 0) {
+       if (i == -1)
+           PRMSG (1,"SocketOpenCLTSServer: Unable to open socket for %s\n",
+                  thistrans->TransName, 0, 0);
+       else
+           PRMSG (1,"SocketOpenCLTSServer: Unable to determine socket type for %s\n",
+                  thistrans->TransName, 0, 0);
        return NULL;
     }
 
-    if ((ciptr = TRANS(SocketOpen) (
-       i, Sockettrans2devtab[i].devcotsname)) == NULL)
-    {
-       PRMSG (1,"SocketOpenCLTSServer: Unable to open socket for %s\n",
-             thistrans->TransName, 0, 0);
-       return NULL;
-    }
 #ifdef IPV6_V6ONLY
     if (Sockettrans2devtab[i].family == AF_INET6)
     {
@@ -677,27 +675,25 @@
 
 {
     XtransConnInfo     ciptr;
-    int                        i;
+    int                        i = -1;
 
     PRMSG (2,
        "SocketReopenCOTSServer(%d, %s)\n", fd, port, 0);
 
     SocketInitOnce();
 
-    if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0)
-    {
-       PRMSG (1,
-       "SocketReopenCOTSServer: Unable to determine socket type for %s\n",
-           thistrans->TransName, 0, 0);
-       return NULL;
-    }
-
-    if ((ciptr = TRANS(SocketReopen) (
-       i, Sockettrans2devtab[i].devcotsname, fd, port)) == NULL)
-    {
-       PRMSG (1,
-           "SocketReopenCOTSServer: Unable to reopen socket for %s\n",
-           thistrans->TransName, 0, 0);
+    while ((i = TRANS(SocketSelectFamily) (i, thistrans->TransName)) >= 0) {
+       if ((ciptr = TRANS(SocketOpen) (
+                i, Sockettrans2devtab[i].devcotsname)) != NULL)
+           break;
+    }
+    if (i < 0) {
+       if (i == -1)
+           PRMSG (1,"SocketReopenCOTSServer: Unable to open socket for %s\n",
+                  thistrans->TransName, 0, 0);
+       else
+           PRMSG (1,"SocketReopenCOTSServer: Unable to determine socket type for 
%s\n",
+                  thistrans->TransName, 0, 0);
        return NULL;
     }
 
@@ -713,27 +709,25 @@
 
 {
     XtransConnInfo     ciptr;
-    int                        i;
+    int                        i = -1;
 
     PRMSG (2,
        "SocketReopenCLTSServer(%d, %s)\n", fd, port, 0);
 
     SocketInitOnce();
 
-    if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0)
-    {
-       PRMSG (1,
-       "SocketReopenCLTSServer: Unable to determine socket type for %s\n",
-             thistrans->TransName, 0, 0);
-       return NULL;
-    }
-
-    if ((ciptr = TRANS(SocketReopen) (
-       i, Sockettrans2devtab[i].devcotsname, fd, port)) == NULL)
-    {
-       PRMSG (1,
-            "SocketReopenCLTSServer: Unable to reopen socket for %s\n",
-            thistrans->TransName, 0, 0);
+    while ((i = TRANS(SocketSelectFamily) (i, thistrans->TransName)) >= 0) {
+       if ((ciptr = TRANS(SocketOpen) (
+                i, Sockettrans2devtab[i].devcotsname)) != NULL)
+           break;
+    }
+    if (i < 0) {
+       if (i == -1)
+           PRMSG (1,"SocketReopenCLTSServer: Unable to open socket for %s\n",
+                  thistrans->TransName, 0, 0);
+       else
+           PRMSG (1,"SocketReopenCLTSServer: Unable to determine socket type for 
%s\n",
+                  thistrans->TransName, 0, 0);
        return NULL;
     }
 

Reply via email to