more empty code for other domains;
authorClaus Gittinger <cg@exept.de>
Thu, 01 May 1997 14:49:43 +0200
changeset 524 8287da54eccf
parent 523 69006d442316
child 525 5891518d17a3
more empty code for other domains; changes tringVal macros; make it compile under NT
Socket.st
--- a/Socket.st	Thu May 01 13:27:07 1997 +0200
+++ b/Socket.st	Thu May 01 14:49:43 1997 +0200
@@ -58,6 +58,8 @@
 #ifdef WIN32
 
 # include <WINSOCK.H>
+# undef NO_SOCKET
+# undef AF_UNIX         /* defines it, but does not support it */
 
 # ifdef __DEF_Array
 #  define Array __DEF_Array
@@ -159,6 +161,23 @@
 #  define PF_RAW AF_RAW
 # endif
 #endif
+#ifdef AF_ISO
+# ifndef PF_ISO
+#  define PF_ISO AF_ISO
+# endif
+#endif
+#ifdef AF_NETBIOS
+# ifndef PF_NETBIOS
+#  define PF_NETBIOS AF_NETBIOS
+# endif
+#endif
+#if defined(AF_CCITT) && (AF_CCITT != AF_X25)
+# ifndef PF_CCITT
+#  define PF_CCITT AF_CCITT
+# endif
+#endif
+
+
 
 #ifdef AF_UNIX
 # ifndef WIN32
@@ -206,24 +225,28 @@
 
 documentation
 "
-    This class provides access to (unix-)sockets for interprocess communication.
+    This class provides access to sockets for interprocess communication.
     The message protocol is preliminary, until someone tells me how
     other smalltalk's socket interfaces look like.
 
-    Also, currently there is almost no support for other than IP 
-    sockets - this will be added in the future.
+    Also, currently there is almost no support for other than IP and UNIX
+    domain sockets - others may be added in the future.
+    (the code is prepared for things like SNA or appletalk support;
+     however, right now, this code is empty and needs work)
+
     Due to historic reasons (I started this class, before I got hold of some
     code using ST-80 Sockets i.e. RemoteInvocation), there is some old interface
     still provided. 
-    This will vanish; use the family:type: or newTCPxxx and newUDPxxx interface,
+    This will vanish; use the #family:type: or #newTCPxxx and #newUDPxxx interfaces,
     together with the bind/listen and accept calls,
     which are meant to be compatible to ST-80's UnixSocketAccessor interface.
 
-    ST/X does not use IPSocketAddress, UDSocketAddress erc; all addressing
+    ST/X does not use IPSocketAddress, UDSocketAddress etc; all addressing
     is done by passing appropriate string- or byteArray objects containing
     the addresses. This may change, too.
 
     TODO: cleanup historic leftovers, implement other than inet domain stuff.
+	  (mhmh - how can I test those ?)
 
     [author:]
 	Claus Gittinger
@@ -919,13 +942,13 @@
 
     if (__isString(aHostName)) {
 	bzero(&sa, sizeof(sa)) ;
-	if ((addr = inet_addr((char *) _stringVal(aHostName))) != -1) {
+	if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) {
 	    /* is Internet addr in octet notation */
 	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); 
 	    sa.sin_family = AF_INET;
 	} else {
 	    /* do we know the host's address? */
-	    if ((hp = gethostbyname((char *) _stringVal(aHostName))) == NULL) {
+	    if ((hp = gethostbyname((char *) __stringVal(aHostName))) == NULL) {
 		DBGPRINTF(("SOCKET: unknown host\n"));
 		RETURN ( nil );
 	    }
@@ -1033,6 +1056,7 @@
     struct servent *servent = NULL;
     char *protocol;
     int tryBoth = 0;
+    short portNo;
 
     if (__isString(aProtocol)) {
 	protocol = __stringVal(aProtocol);
@@ -1042,25 +1066,27 @@
     }
 
     if (__isSmallInteger(aNameOrNumber)) {
-	servent = getservbyport(htons(_intVal(aNameOrNumber)), protocol);
+	portNo = __intVal(aNameOrNumber);
+	servent = getservbyport(htons(portNo), protocol);
 	if (servent != NULL) {
 	    RETURN ( aNameOrNumber );
 	}
 	if (tryBoth) {
-	    servent = getservbyport(htons(_intVal(aNameOrNumber)), "udp");
+	    servent = getservbyport(htons(portNo), "udp");
 	    if (servent != NULL) {
 		RETURN ( aNameOrNumber );
 	    }
 	}
 	RETURN ( aNameOrNumber );
     }
-    if (__isString(aNameOrNumber)) {
-	servent = getservbyname((char *) _stringVal(aNameOrNumber), protocol);
+
+    if (__isString(aNameOrNumber) || __isSymbol(aNameOrNumber)) {
+	servent = getservbyname((char *) __stringVal(aNameOrNumber), protocol);
 	if (servent != NULL) {
 	    RETURN ( __MKSMALLINT(ntohs(servent->s_port)) );
 	}
 	if (tryBoth) {
-	    servent = getservbyname((char *) _stringVal(aNameOrNumber), "udp");
+	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
 	    if (servent != NULL) {
 		RETURN ( __MKSMALLINT(ntohs(servent->s_port)) );
 	    }
@@ -1082,20 +1108,22 @@
 %{
 #ifndef NO_SOCKET
     struct servent *servent = NULL;
+    short portNo;
 
     if (__isSmallInteger(aNameOrNumber)) {
-	servent = getservbyport(htons(_intVal(aNameOrNumber)), "tcp") ;
+	portNo = __intVal(aNameOrNumber);
+	servent = getservbyport(htons(portNo), "tcp") ;
 	if (servent == NULL) {
-	    servent = getservbyport(htons(_intVal(aNameOrNumber)), "udp") ;
+	    servent = getservbyport(htons(portNo), "udp") ;
 	    if (servent == NULL) {
 		RETURN ( nil );
 	    }
 	}
     } else {
 	if (__isString(aNameOrNumber)) {
-	    servent = getservbyname((char *) _stringVal(aNameOrNumber), "tcp");
+	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp");
 	    if (servent == NULL) {
-		servent = getservbyname((char *) _stringVal(aNameOrNumber), "udp");
+		servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
 		if (servent == NULL) {
 		    RETURN ( nil );
 		}
@@ -1218,7 +1246,7 @@
     int nInstVars, nInstBytes, objSize;
     int sock;
     union {
-        struct sockaddr_in in;
+	struct sockaddr_in in;
     } sa;
     int alen;
     int n;
@@ -1226,119 +1254,135 @@
     int flags = 0;
 
     if (fp != nil) {
-        sock = fileno(__FILEVal(fp));
-
-        oClass = __Class(aDataBuffer);
-        switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
-            case BYTEARRAY:
-            case WORDARRAY:
-            case LONGARRAY:
-            case FLOATARRAY:
-            case DOUBLEARRAY:
-                break;
-            default:
-                goto bad;
-        }
-
-        nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
-        nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
-        objSize = _Size(aDataBuffer) - nInstBytes;
-        cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
-        if (__isSmallInteger(startIndex)) {
-            cp += __intVal(startIndex);
-            objSize -= __intVal(startIndex);
-        }
-        if (__isSmallInteger(nBytes)) {
-            if (__intVal(nBytes) < objSize) {
-                objSize = __intVal(nBytes);
-            }
-        }
-
-        __BEGIN_INTERRUPTABLE__
-        do {
-            if (addrBytes == nil) {
-                n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) 0, 0);
-            } else {
-                n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) &sa, &alen);
-            }
-        } while ((n < 0) && (errno == EINTR));
-        __END_INTERRUPTABLE__
-
-        if (n >= 0) {
-            if (addrBytes != nil) {
-                oClass = __Class(addrBytes);
-                if ((_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) != BYTEARRAY) 
-                    goto bad;
-                nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
-                nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
-                objSize = _Size(addrBytes) - nInstBytes;
-                cp = (char *)__InstPtr(addrBytes) + nInstBytes;
-                if (objSize < alen) 
-                    goto bad;
-
-                myDomain = __INST(domain);
+	sock = fileno(__FILEVal(fp));
+
+	oClass = __Class(aDataBuffer);
+	switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+	    case BYTEARRAY:
+	    case WORDARRAY:
+	    case LONGARRAY:
+	    case FLOATARRAY:
+	    case DOUBLEARRAY:
+		break;
+	    default:
+		goto bad;
+	}
+
+	nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
+	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
+	objSize = _Size(aDataBuffer) - nInstBytes;
+	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
+	if (__isSmallInteger(startIndex)) {
+	    cp += __intVal(startIndex);
+	    objSize -= __intVal(startIndex);
+	}
+	if (__isSmallInteger(nBytes)) {
+	    if (__intVal(nBytes) < objSize) {
+		objSize = __intVal(nBytes);
+	    }
+	}
+
+	__BEGIN_INTERRUPTABLE__
+	do {
+	    if (addrBytes == nil) {
+		n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) 0, 0);
+	    } else {
+		n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) &sa, &alen);
+	    }
+	} while ((n < 0) && (errno == EINTR));
+	__END_INTERRUPTABLE__
+
+	if (n >= 0) {
+	    if (addrBytes != nil) {
+		oClass = __Class(addrBytes);
+		if ((_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) != BYTEARRAY) 
+		    goto bad;
+		nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
+		nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
+		objSize = _Size(addrBytes) - nInstBytes;
+		cp = (char *)__InstPtr(addrBytes) + nInstBytes;
+		if (objSize < alen) 
+		    goto bad;
+
+		myDomain = __INST(domain);
 # ifdef AF_UNIX
-                if (myDomain == @symbol(unix)) {
-                    cp[0] = (sa.in.sin_addr.s_addr >> 24) & 0xFF;
-                    cp[2] = (sa.in.sin_addr.s_addr >> 16) & 0xFF;
-                    cp[3] = (sa.in.sin_addr.s_addr >> 8) & 0xFF;
-                    cp[4] = (sa.in.sin_addr.s_addr >> 0) & 0xFF;
-                    alen = 4;
-                }
+		if (myDomain == @symbol(unix)) {
+		    cp[0] = (sa.in.sin_addr.s_addr >> 24) & 0xFF;
+		    cp[2] = (sa.in.sin_addr.s_addr >> 16) & 0xFF;
+		    cp[3] = (sa.in.sin_addr.s_addr >> 8) & 0xFF;
+		    cp[4] = (sa.in.sin_addr.s_addr >> 0) & 0xFF;
+		    alen = 4;
+		}
 # endif
-                /*
-                 * XXXX add addressing stuff for other domains here ...
-                 */
+		/*
+		 * XXXX add addressing stuff for other domains here ...
+		 */
 # ifdef AF_X25
-                if (myDomain == @symbol(x25)) {
-                }
+		if (myDomain == @symbol(x25)) {
+		}
 # endif
 # ifdef AF_NS
-                if (myDomain == @symbol(ns)) {
-                }
+		if (myDomain == @symbol(ns)) {
+		}
 # endif
 # ifdef AF_APPLETALK
-                if (myDomain == @symbol(appletalk)) {
-                }
+		if (myDomain == @symbol(appletalk)) {
+		}
 # endif
 # ifdef AF_SNA
-                if (myDomain == @symbol(sna)) {
-                }
+		if (myDomain == @symbol(sna)) {
+		}
 # endif
 # ifdef AF_NS
-                if (myDomain == @symbol(xns)) {
-                }
+		if (myDomain == @symbol(xns)) {
+		}
 # endif
 # ifdef AF_RAW
-                if (myDomain == @symbol(raw)) {
-                }
+		if (myDomain == @symbol(raw)) {
+		}
+# endif
+# ifdef AF_ISO
+		if (myDomain == @symbol(iso)) {
+		}
+# endif
+# ifdef AF_DECnet
+		if (myDomain == @symbol(decnet)) {
+		}
 # endif
-
-                addrLen = __MKSMALLINT(alen);
-            }
-        }
-        if (n < 0) {
-            __INST(lastErrorNumber) = __MKSMALLINT(errno);
-        }
-        nReceived = __MKSMALLINT(n);
+# ifdef AF_NETBIOS
+		if (myDomain == @symbol(decnet)) {
+		}
+# endif
+# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
+		if (myDomain == @symbol(ccitt)) {
+		}
+# endif
+
+		addrLen = __MKSMALLINT(alen);
+	    }
+	}
+	if (n < 0) {
+	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
+	}
+	nReceived = __MKSMALLINT(n);
     }
 #endif
 bad: ;
 %}.
     nReceived notNil ifTrue:[
-        nReceived < 0 ifTrue:[
-            'Socket [warning]: ' infoPrint.
-            (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
-        ].
-        addrLen notNil ifTrue:[
-            anAddressBuffer class isBytes ifTrue:[
-                anAddressBuffer replaceFrom:1 to:addrLen with:addrBytes
-            ] ifFalse:[
-                "/ can be SocketAddress for ST-80 compatibility
-                anAddressBuffer hostAddress:(addrBytes copyTo:addrLen)
-            ].
-        ].
-        ^ nReceived
+	nReceived < 0 ifTrue:[
+	    'Socket [warning]: ' infoPrint.
+	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
+	].
+	addrLen notNil ifTrue:[
+	    anAddressBuffer class isBytes ifTrue:[
+		anAddressBuffer replaceFrom:1 to:addrLen with:addrBytes
+	    ] ifFalse:[
+		"/ can be SocketAddress for ST-80 compatibility
+		anAddressBuffer hostAddress:(addrBytes copyTo:addrLen)
+	    ].
+	].
+	^ nReceived
     ].
     "
      arrive here if you try to receive into an invalid buffer
@@ -1574,16 +1618,16 @@
      i.e. address must always be nil.
 
      The interpretation of portNrOrName depends on the domain:
-        inet domain uses (4byte) byteArray like internet numbers,
-        unix domain uses pathname strings,
-        others use whatever will come up in the future
+	inet domain uses (4byte) byteArray like internet numbers,
+	unix domain uses pathname strings,
+	others use whatever will come up in the future
 
      The reuse boolean argument controls if the SO_REUSEADDR socket option
      is to be set (to avoid the 'bind: address in use' error).
     "
 
     filePointer isNil ifTrue:[
-        ^ self error:'not a valid socket'
+	^ self error:'not a valid socket'
     ].
 %{
 #ifndef NO_SOCKET
@@ -1591,8 +1635,10 @@
     OBJ myDomain;
     int sock;
     union {
-        struct sockaddr_in in;
-        struct sockaddr_un un;
+	struct sockaddr_in in;
+# ifdef AF_UNIX
+	struct sockaddr_un un;
+# endif /* AF_UNIX */
     } sa;
     int sockaddr_size;
     int ret;
@@ -1600,102 +1646,102 @@
     int ok;
 
     if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) {
-        DBGPRINTF(("SOCKET: invalid domain arg\n"));
-        RETURN (false);
+	DBGPRINTF(("SOCKET: invalid domain arg\n"));
+	RETURN (false);
     }
 
     ok = 0;
     myDomain = __INST(domain);
 # ifdef AF_INET
     if (myDomain == @symbol(inet)) {
-        /*
-         * INET addresses - port must be a smallinteger or nil
-         */
-        sa.in.sin_family = AF_INET;
-
-        if (portNrOrName == nil) {
-            sa.in.sin_port = 0;
-        } else {
-            if (! __isSmallInteger(portNrOrName)) {
-                DBGPRINTF(("SOCKET: invalid port arg\n"));
-                RETURN (false);
-            }
-            sa.in.sin_port = htons((u_short) _intVal(portNrOrName));
-        }
-
-        /*
-         * INET addresses - addr must be nil, integer or byteArray
-         */
-        if (address == nil) {
-            sa.in.sin_addr.s_addr = htonl(INADDR_ANY);
-        } else {
-            if (__isInteger(address)) {
-                sa.in.sin_addr.s_addr = htonl(__longIntVal(address));
-            } else {
-                if (__isByteArray(address)) {
-                    unsigned char *cp;
-                    int n;
-
-                    cp = __ByteArrayInstPtr(address)->ba_element;
-                    n = __byteArraySize(address);
-                    if (n > 4) n = 4;
-                    bcopy(cp, &sa.in.sin_addr.s_addr, n);
-                } else {
-                    char *hostName;
-                    unsigned addr;
-                    struct hostent *hp ;
-
-                    if (! __isString(address)) {
-                        DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
-                        RETURN (false);
-                    }
-
-                    hostName = (char *) _stringVal(address);
-
-                    if ((addr = inet_addr(hostName)) != -1) {
-                        /* 
-                         * is Internet addr in octet notation 
-                         */
-                        bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
-                    } else {
-                        /* 
-                         * do we know the host's address? 
-                         */
-                        if ((hp = gethostbyname(hostName)) == NULL) {
-                            DBGPRINTF(("SOCKET: unknown host:%s\n", hostName));
-                            RETURN (false);
-                        }
-                        bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
-                        sa.in.sin_family = hp->h_addrtype;
-                    }
-                }
-            }
-        }
-        DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port));
-        sockaddr_size = sizeof(struct sockaddr_in);
-        ok = 1;
+	/*
+	 * INET addresses - port must be a smallinteger or nil
+	 */
+	sa.in.sin_family = AF_INET;
+
+	if (portNrOrName == nil) {
+	    sa.in.sin_port = 0;
+	} else {
+	    if (! __isSmallInteger(portNrOrName)) {
+		DBGPRINTF(("SOCKET: invalid port arg\n"));
+		RETURN (false);
+	    }
+	    sa.in.sin_port = htons((u_short) _intVal(portNrOrName));
+	}
+
+	/*
+	 * INET addresses - addr must be nil, integer or byteArray
+	 */
+	if (address == nil) {
+	    sa.in.sin_addr.s_addr = htonl(INADDR_ANY);
+	} else {
+	    if (__isInteger(address)) {
+		sa.in.sin_addr.s_addr = htonl(__longIntVal(address));
+	    } else {
+		if (__isByteArray(address)) {
+		    unsigned char *cp;
+		    int n;
+
+		    cp = __ByteArrayInstPtr(address)->ba_element;
+		    n = __byteArraySize(address);
+		    if (n > 4) n = 4;
+		    bcopy(cp, &sa.in.sin_addr.s_addr, n);
+		} else {
+		    char *hostName;
+		    unsigned addr;
+		    struct hostent *hp ;
+
+		    if (! __isString(address)) {
+			DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
+			RETURN (false);
+		    }
+
+		    hostName = (char *) __stringVal(address);
+
+		    if ((addr = inet_addr(hostName)) != -1) {
+			/* 
+			 * is Internet addr in octet notation 
+			 */
+			bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
+		    } else {
+			/* 
+			 * do we know the host's address? 
+			 */
+			if ((hp = gethostbyname(hostName)) == NULL) {
+			    DBGPRINTF(("SOCKET: unknown host:%s\n", hostName));
+			    RETURN (false);
+			}
+			bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
+			sa.in.sin_family = hp->h_addrtype;
+		    }
+		}
+	    }
+	}
+	DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port));
+	sockaddr_size = sizeof(struct sockaddr_in);
+	ok = 1;
     }
 # endif
 # ifdef AF_UNIX
     if (myDomain == @symbol(unix)) {
-        char *pathName;
-        int l;
-
-        if (! __isString(portNrOrName)) {
-            DBGPRINTF(("SOCKET: invalid port (pathname) arg\n"));
-            RETURN (false);
-        }
-        pathName = __stringVal(portNrOrName);
-        l = strlen(pathName);
-        if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) {
-            DBGPRINTF(("SOCKET: pathname too long\n"));
-            RETURN (false);
-        }
-
-        strcpy(sa.un.sun_path, pathName);
-        sa.un.sun_family = AF_UNIX;
-        sockaddr_size = l + sizeof ( sa.un.sun_family );
-        ok = 1;
+	char *pathName;
+	int l;
+
+	if (! __isString(portNrOrName)) {
+	    DBGPRINTF(("SOCKET: invalid port (pathname) arg\n"));
+	    RETURN (false);
+	}
+	pathName = __stringVal(portNrOrName);
+	l = strlen(pathName);
+	if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) {
+	    DBGPRINTF(("SOCKET: pathname too long\n"));
+	    RETURN (false);
+	}
+
+	strcpy(sa.un.sun_path, pathName);
+	sa.un.sun_family = AF_UNIX;
+	sockaddr_size = l + sizeof ( sa.un.sun_family );
+	ok = 1;
     }
 # endif
     /*
@@ -1713,6 +1759,10 @@
     if (myDomain == @symbol(appletalk)) {
     }
 # endif
+# ifdef AF_DECnet
+    if (myDomain == @symbol(decnet)) {
+    }
+# endif
 # ifdef AF_SNA
     if (myDomain == @symbol(sna)) {
     }
@@ -1725,32 +1775,44 @@
     if (myDomain == @symbol(raw)) {
     }
 # endif
+# ifdef AF_ISO
+    if (myDomain == @symbol(iso)) {
+    }
+# endif
+# ifdef AF_NETBIOS
+    if (myDomain == @symbol(decnet)) {
+    }
+# endif
+# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
+    if (myDomain == @symbol(ccitt)) {
+    }
+# endif
 
     if (! ok) {
-        DBGPRINTF(("SOCKET: unsupported domain\n"));
-        RETURN (false);
+	DBGPRINTF(("SOCKET: unsupported domain\n"));
+	RETURN (false);
     }
 
     sock = fileno(__FILEVal(t));
 
 # ifdef SO_REUSEADDR
     if (reuse == true) {
-        if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
-            DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
-        }
+	if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
+	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
+	}
     }
 # endif /* SO_REUSEADDR */
 
     __BEGIN_INTERRUPTABLE__
     do {
-        ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
+	ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
     } while ((ret < 0) && (errno == EINTR));
     __END_INTERRUPTABLE__
 
     if (ret < 0) {
-        DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno));
-        __INST(lastErrorNumber) = __MKSMALLINT(errno);
-        RETURN (false);
+	DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno));
+	__INST(lastErrorNumber) = __MKSMALLINT(errno);
+	RETURN (false);
     }
 
     __INST(port) = portNrOrName; __STORE(self, portNrOrName);
@@ -1758,21 +1820,21 @@
 # ifdef AF_INET
 
     if (myDomain == @symbol(inet)) {
-        if (! __isSmallInteger(portNrOrName)
-         || (portNrOrName == __MKSMALLINT(0))) {
-            int p;
-
-            /*
-             * INET anonymous port - get the actual portNr
-             */
-            if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
-                DBGPRINTF(("SOCKET: cannot get peername\n"));
-            } else {
-                DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
-                p = ntohs(sa.in.sin_port);
-                __INST(port) = __MKSMALLINT(p);
-            }
-        }
+	if (! __isSmallInteger(portNrOrName)
+	 || (portNrOrName == __MKSMALLINT(0))) {
+	    int p;
+
+	    /*
+	     * INET anonymous port - get the actual portNr
+	     */
+	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
+		DBGPRINTF(("SOCKET: cannot get peername\n"));
+	    } else {
+		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
+		p = ntohs(sa.in.sin_port);
+		__INST(port) = __MKSMALLINT(p);
+	    }
+	}
     }
 # endif
 #else /* NO_SOCKET */
@@ -1783,8 +1845,8 @@
 
     "
      (Socket domain:#inet type:#stream)
-         bindTo:9999
-         address:nil
+	 bindTo:9999
+	 address:nil
     "
 !
 
@@ -1818,7 +1880,9 @@
     int sock, newSock;
     union {
 	struct sockaddr_in in ;
+# ifdef AF_UNIX
 	struct sockaddr_un un ;
+# endif
     } sa;
     int alen, alen0;
     struct hostent *he ;
@@ -1841,6 +1905,49 @@
 	alen0 = sizeof(sa.un);
     }
 #endif
+    /*
+     * XXXX add addressing stuff for other domains here ...
+     */
+# ifdef AF_X25
+    if (__INST(domain) == @symbol(x25)) {
+    }
+# endif
+# ifdef AF_NS
+    if (__INST(domain) == @symbol(ns)) {
+    }
+# endif
+# ifdef AF_APPLETALK
+    if (__INST(domain) == @symbol(appletalk)) {
+    }
+# endif
+# ifdef AF_DECnet
+    if (__INST(domain) == @symbol(decnet)) {
+    }
+# endif
+# ifdef AF_SNA
+    if (__INST(domain) == @symbol(sna)) {
+    }
+# endif
+# ifdef AF_NS
+    if (__INST(domain) == @symbol(xns)) {
+    }
+# endif
+# ifdef AF_RAW
+    if (__INST(domain) == @symbol(raw)) {
+    }
+# endif
+# ifdef AF_ISO
+    if (__INST(domain) == @symbol(iso)) {
+    }
+# endif
+# ifdef AF_NETBIOS
+    if (__INST(domain) == @symbol(decnet)) {
+    }
+# endif
+# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
+    if (__INST(domain) == @symbol(ccitt)) {
+    }
+# endif
 
     __BEGIN_INTERRUPTABLE__
     do {
@@ -1886,6 +1993,49 @@
 	/* nothing to be done here */
     }
 #endif
+    /*
+     * XXXX add addressing stuff for other domains here ...
+     */
+# ifdef AF_X25
+    if (__INST(domain) == @symbol(x25)) {
+    }
+# endif
+# ifdef AF_NS
+    if (__INST(domain) == @symbol(ns)) {
+    }
+# endif
+# ifdef AF_APPLETALK
+    if (__INST(domain) == @symbol(appletalk)) {
+    }
+# endif
+# ifdef AF_DECnet
+    if (__INST(domain) == @symbol(decnet)) {
+    }
+# endif
+# ifdef AF_SNA
+    if (__INST(domain) == @symbol(sna)) {
+    }
+# endif
+# ifdef AF_NS
+    if (__INST(domain) == @symbol(xns)) {
+    }
+# endif
+# ifdef AF_RAW
+    if (__INST(domain) == @symbol(raw)) {
+    }
+# endif
+# ifdef AF_ISO
+    if (__INST(domain) == @symbol(iso)) {
+    }
+# endif
+# ifdef AF_NETBIOS
+    if (__INST(domain) == @symbol(decnet)) {
+    }
+# endif
+# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
+    if (__INST(domain) == @symbol(ccitt)) {
+    }
+# endif
 
     /* 
      * make it a FILE * 
@@ -1956,7 +2106,9 @@
     OBJ myDomain;
     union {
 	struct sockaddr_in in ;
+# ifdef AF_UNIX
 	struct sockaddr_un un;
+# endif
     } sa;
     struct hostent *hp ;
     int a, sock ;
@@ -1998,27 +2150,27 @@
 	    bcopy(cp, &sa.in.sin_addr.s_addr, n);
 	} else {
 	    if (! __isString(hostOrPathName)) {
-	        DBGPRINTF(("SOCKET: invalid hostname arg\n"));
-	        RETURN (false);
+		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
+		RETURN (false);
 	    }
 
-	    hostName = (char *) _stringVal(hostOrPathName);
+	    hostName = (char *) __stringVal(hostOrPathName);
 
 	    if ((addr = inet_addr(hostName)) != -1) {
-	        /* 
-	         * is Internet addr in octet notation 
-	         */
-	        bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
+		/* 
+		 * is Internet addr in octet notation 
+		 */
+		bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
 	    } else {
-	        /* 
-	         * do we know the host's address? 
-	         */
-	        if ((hp = gethostbyname(hostName)) == NULL) {
+		/* 
+		 * do we know the host's address? 
+		 */
+		if ((hp = gethostbyname(hostName)) == NULL) {
 		    DBGPRINTF(("SOCKET: unknown host:%s\n", hostName));
 		    RETURN (false);
-	        }
-	        bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
-	        sa.in.sin_family = hp->h_addrtype;
+		}
+		bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
+		sa.in.sin_family = hp->h_addrtype;
 	    }
 	}
 
@@ -2065,6 +2217,10 @@
     if (myDomain == @symbol(appletalk)) {
     }
 #endif
+# ifdef AF_DECnet
+    if (myDomain == @symbol(decnet)) {
+    }
+# endif
 #ifdef AF_NS 
     if (myDomain == @symbol(xns)) {
     }
@@ -2077,6 +2233,18 @@
     if (myDomain == @symbol(raw)) {
     }
 #endif
+# ifdef AF_ISO
+    if (myDomain == @symbol(iso)) {
+    }
+# endif
+# ifdef AF_NETBIOS
+    if (myDomain == @symbol(decnet)) {
+    }
+# endif
+# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
+    if (myDomain == @symbol(ccitt)) {
+    }
+# endif
 
     if (! ok) {
 	DBGPRINTF(("SOCKET: unsupported domain\n"));
@@ -2285,7 +2453,7 @@
     |p|
 
     port == 0 ifTrue:[
-        p := self getPort.
+	p := self getPort.
 	p notNil ifTrue:[
 	    port := p
 	]
@@ -2386,8 +2554,23 @@
 	dom = AF_RAW;
     } else
 #endif
+# ifdef AF_ISO
+    if (domainArg == @symbol(iso)) {
+	dom = AF_ISO;
+    }
+# endif
+# ifdef AF_NETBIOS
+    if (domainArg == @symbol(netbios)) {
+	dom = AF_NETBIOS;
+    }
+# endif
+# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
+    if (domainArg == @symbol(ccitt)) {
+	dom = AF_CCITT;
+    }
+# endif
     {
-	DBGPRINTF(("SOCKET: unknown domain <%s>\n", _stringVal(domainArg)));
+	DBGPRINTF(("SOCKET: unknown domain <%s>\n", __stringVal(domainArg)));
 	RETURN ( nil );
     }
 
@@ -2412,7 +2595,7 @@
     else
 #endif
     {
-	DBGPRINTF(("SOCKET: bad type <%s>\n", _stringVal(typeArg)));
+	DBGPRINTF(("SOCKET: bad type <%s>\n", __stringVal(typeArg)));
 	RETURN ( nil );
     }
 
@@ -2500,7 +2683,7 @@
 
     if ((hostName != nil) && __isString(hostName)){
 	bzero(&sa, sizeof(sa)) ;
-	if ((addr = inet_addr((char *) _stringVal(hostName))) != -1) {
+	if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) {
 	    /* 
 	     * is Internet addr in octet notation 
 	     */
@@ -2509,7 +2692,7 @@
 	    /* 
 	     * do we know the host's address? 
 	     */
-	    if ((hp = gethostbyname((char *) _stringVal(hostName))) == NULL) {
+	    if ((hp = gethostbyname((char *) __stringVal(hostName))) == NULL) {
 		DBGPRINTF(("SOCKET: unknown host\n"));
 		RETURN ( nil );
 	    }
@@ -2634,7 +2817,7 @@
 
     if (hostName != nil) {
 	bzero(&sa, sizeof(sa)) ;
-	if ((addr = inet_addr((char *) _stringVal(hostName))) != -1) {
+	if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) {
 	    /* 
 	     * is Internet addr in octet notation 
 	     */
@@ -2645,7 +2828,7 @@
 	     * is hostname - 
 	     * do we know the host's address? 
 	     */
-	    if ((hp = gethostbyname((char *) _stringVal(hostName))) == NULL) {
+	    if ((hp = gethostbyname((char *) __stringVal(hostName))) == NULL) {
 		DBGPRINTF(("SOCKET: unknown host\n"));
 		RETURN ( nil );
 	    }
@@ -2794,5 +2977,5 @@
 !Socket class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.83 1997-03-28 17:28:12 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.84 1997-05-01 12:49:43 cg Exp $'
 ! !