Socket.st
changeset 1274 f257a1b16b4d
parent 1263 23161346a162
child 1278 7251c65b8d38
--- a/Socket.st	Mon Jul 14 13:10:40 2003 +0200
+++ b/Socket.st	Mon Jul 14 13:11:15 2003 +0200
@@ -1645,60 +1645,22 @@
      If the host is unknown, return nil.
      This is the reverse operation to #hostWithIpAddress:."
 
-%{  /* STACK: 100000 */
-#if !defined(NO_SOCKET) && defined(AF_INET)
-    struct sockaddr_in sa ;
-    struct hostent *hp ;
-    long addr;
-    OBJ rslt;
-
-    sa.sin_family = -1;
-
-    if (__isString(aHostName)) {
-	bzero(&sa, sizeof(sa)) ;
-	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? */
-	    GETHOSTBYNAME(hp, __stringVal(aHostName))
-	    if (hp == NULL) {
-		DBGPRINTF(("SOCKET: unknown ip host: %s\n", __stringVal(aHostName)));
-		RETURN ( nil );
-	    }
-	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
-	    sa.sin_family = hp->h_addrtype;
-	}
-    }
-
-    /* if the addressing family is not AF_INET, Return nil */
-    if (sa.sin_family != AF_INET) {
-	DBGPRINTF(("SOCKET: not an ip host\n"));
-	RETURN ( nil );
-    }
-
-    sa.sin_addr.s_addr = ntohl(sa.sin_addr.s_addr);    
-    rslt = __BYTEARRAY_NEW_INT(4);
-    if (rslt != nil) {
-	__ByteArrayInstPtr(rslt)->ba_element[0] = (sa.sin_addr.s_addr >> 24) & 0xFF;
-	__ByteArrayInstPtr(rslt)->ba_element[1] = (sa.sin_addr.s_addr >> 16) & 0xFF;
-	__ByteArrayInstPtr(rslt)->ba_element[2] = (sa.sin_addr.s_addr >> 8) & 0xFF;
-	__ByteArrayInstPtr(rslt)->ba_element[3] = (sa.sin_addr.s_addr >> 0) & 0xFF;
-       RETURN (rslt);
-    }
-#endif
-%}.
-    ^ nil
+    NameLookupError 
+        handle:[:ex | 
+            ^ nil
+        ]
+        do:[
+            ^ (IPSocketAddress hostName:aHostName) address
+        ]
 
     "
      Socket ipAddressOfHost:'localhost' 
-     Socket ipAddressOfHost:'exept'    
-     Socket ipAddressOfHost:'1.2.3.4'    
-     Socket ipAddressOfHost:'193.15.16.17'    
-     Socket ipAddressOfHost:'josef'     
-     Socket ipAddressOfHost:'styx.com'  
-     Socket hostWithIpAddress:(Socket ipAddressOfHost:'localhost') 
+     Socket ipAddressOfHost:'exept'     
+     Socket ipAddressOfHost:'1.2.3.4'   
+     Socket ipAddressOfHost:'193.15.16.17'
+     Socket ipAddressOfHost:'josef'      
+     Socket ipAddressOfHost:'styx.com' 
+     Socket hostWithIpAddress:(Socket ipAddressOfHost:'localhost')'localhost'  
      Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1') 
     "
 !
@@ -1709,56 +1671,20 @@
      If the host is unknown, return nil.
      This is the reverse operation to #hostWithIpV6Address:."
 
-%{  /* STACK: 100000 */
-#if !defined(NO_SOCKET) && defined(AF_INET6)
-    struct sockaddr_in6 sa;
-    struct hostent *hp ;
-    long addr;
-    OBJ rslt;
-
-    sa.sin6_family = -1;
-
-    if (__isString(aHostName)) {
-	bzero(&sa, sizeof(sa)) ;
-#if 0
-	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 
-#endif
-	{
-	    /* do we know the host's address? */
-	    GETHOSTBYNAME(hp, __stringVal(aHostName))
-	    if (hp == NULL) {
-		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(aHostName)));
-		RETURN ( nil );
-	    }
-	    bcopy(hp->h_addr, (char *) &sa.sin6_addr, hp->h_length) ;
-	    sa.sin6_family = hp->h_addrtype;
-	}
-    }
-
-    /* if the addressing family is not AF_INET, Return nil */
-    if (sa.sin6_family != AF_INET) {
-	DBGPRINTF(("SOCKET: not an ipv6 host\n"));
-	RETURN ( nil );
-    }
-
-    rslt = __BYTEARRAY_NEW_INT(hp->h_length);
-    if (rslt != nil) {
-	bcopy(sa.sin6_addr.s6_addr, __ByteArrayInstPtr(rslt)->ba_element, hp->h_length);
-       RETURN (rslt);
-    }
-#endif
-%}.
-    ^ nil
+    NameLookupError 
+        handle:[:ex | 
+            ^ nil
+        ]
+        do:[
+            ^ (IPv6SocketAddress hostName:aHostName) address
+        ]
 
     "
-     Socket ipV6AddressOfHost:'localhost' 
-     Socket ipV6AddressOfHost:'exept'    
+     Socket ipV6AddressOfHost:'localhost'  
+     Socket ipV6AddressOfHost:'exept'      
+     Socket ipV6AddressOfHost:'exept.exept.de'      
+     Socket ipV6AddressOfHost:'www.google.de'      
      Socket ipV6AddressOfHost:'1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16'    
-     Socket ipV6AddressOfHost:'193.15.16.17'    
      Socket ipV6AddressOfHost:'josef'     
      Socket ipV6AddressOfHost:'styx.com'  
      Socket hostWithIpV6Address:(Socket ipV6AddressOfHost:'localhost') 
@@ -4781,5 +4707,5 @@
 !Socket class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.180 2003-07-09 16:18:48 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.181 2003-07-14 11:11:15 cg Exp $'
 ! !