getNetworkMacAddress
authorca
Mon, 26 Jan 2004 17:07:57 +0100
changeset 7840 a57bac3c9c68
parent 7839 d6d9fac8b4db
child 7841 c25e1dc957b8
getNetworkMacAddress
Win32OperatingSystem.st
--- a/Win32OperatingSystem.st	Mon Jan 26 16:12:32 2004 +0100
+++ b/Win32OperatingSystem.st	Mon Jan 26 17:07:57 2004 +0100
@@ -173,15 +173,17 @@
 # undef Signal
 # undef Delay
 
-# define NO_GETADAPTERSINFO
+/* # define NO_GETADAPTERSINFO
+*/
 
 # include <stdarg.h> /* */
 # ifndef WINDOWS_H_INCLUDED
 #  define WINDOWS_H_INCLUDED
 #  include <windows.h>
 # endif
+
 # ifndef NO_GETADAPTERSINFO
-#  include <iphlpapi.h> /* req'd for GetAdaptersInfo */
+#  include <iphlpapi.h>
 # endif
 
 # if !defined(__BORLANDC__)
@@ -397,48 +399,48 @@
     tv.tv_usec = 0;
 
     if (readMode) {
-        n = select (sock + 1, & fds, NULL, NULL, & tv);
+	n = select (sock + 1, & fds, NULL, NULL, & tv);
     } else {
-        n = select (sock + 1, NULL, & fds, NULL, & tv);
+	n = select (sock + 1, NULL, & fds, NULL, & tv);
     }
 
     if (n == 0) {
-        return (0);
+	return (0);
     }
 
     if (n > 0) {
-        return ((FD_ISSET (sock, & fds)) ? 1 : 0);
+	return ((FD_ISSET (sock, & fds)) ? 1 : 0);
     }
 
     switch (WSAGetLastError()) {
-        case WSAENOTSOCK:
-            if (readMode) {
-
-                DWORD  w = 0;
-                HANDLE h = (HANDLE) _get_osfhandle (aFD);
-
-                if (PeekNamedPipe (h, 0, 0, 0, & w, 0)) {
-                    if( !__isWinNT || w > 0 )
-                        return (1);
-
-                    return (0);
-                }
-                return (-1);
-            }
-            /* in writeMode we return allways true for none-sockets */
-            return (1);
-
-        case WSAEINPROGRESS:
-        case WSAEWOULDBLOCK: return (0);
-
-        default: return (1);
+	case WSAENOTSOCK:
+	    if (readMode) {
+
+		DWORD  w = 0;
+		HANDLE h = (HANDLE) _get_osfhandle (aFD);
+
+		if (PeekNamedPipe (h, 0, 0, 0, & w, 0)) {
+		    if( !__isWinNT || w > 0 )
+			return (1);
+
+		    return (0);
+		}
+		return (-1);
+	    }
+	    /* in writeMode we return allways true for none-sockets */
+	    return (1);
+
+	case WSAEINPROGRESS:
+	case WSAEWOULDBLOCK: return (0);
+
+	default: return (1);
     }
 
     return (0);
 }
 
-#define _canReadWithoutBlocking(fd)	_canAccessIOWithoutBlocking(fd, 1)
-#define _canWriteWithoutBlocking(fd)	_canAccessIOWithoutBlocking(fd, 0)
+#define _canReadWithoutBlocking(fd)     _canAccessIOWithoutBlocking(fd, 1)
+#define _canWriteWithoutBlocking(fd)    _canAccessIOWithoutBlocking(fd, 0)
 
 
 %}
@@ -5234,19 +5236,19 @@
 getLanguage
     "return the domain this host is in.
      Notice:
-        not all systems support this; on some, 'unknown' is returned."
+	not all systems support this; on some, 'unknown' is returned."
     
     |name|
 
     name := self getEnvironment:'LANG'.
     name isNil ifTrue:[
-        "/ ok, search the registry ...
-        "/ under XP, it is found there ...
-        name := RegistryEntry stringValueFor:'sLanguage'
-                    atKey:'HKEY_CURRENT_USER\Control Panel\International'.
-        name notNil ifTrue:[
-            name := self mapLanguage:name.
-        ].
+	"/ ok, search the registry ...
+	"/ under XP, it is found there ...
+	name := RegistryEntry stringValueFor:'sLanguage'
+		    atKey:'HKEY_CURRENT_USER\Control Panel\International'.
+	name notNil ifTrue:[
+	    name := self mapLanguage:name.
+	].
     ].
     ^ name
 
@@ -5515,9 +5517,10 @@
      for each interface 
     "
 
-    |nAdapters rawData|
-
-    rawData := ByteArray new:(32 * 6).
+    |info nAdapters rawData entry
+     name description macAddress ipAddress ipAddressMask|
+
+    rawData := Array new:50.
 %{
 #ifndef NO_GETADAPTERSINFO
     IP_ADAPTER_INFO AdapterInfo[32];
@@ -5535,10 +5538,31 @@
 
 	bP = __byteArrayVal(rawData);
 	do {
+/*
+ * temporary undef String to avoid a #define-conflict
+ * between ST/X's String and Windows String typedef
+ */
+# undef String
+	    name = __MKSTRING(pAdapterInfo->AdapterName);
+	    description = __MKSTRING(pAdapterInfo->Description);
+	    macAddress = __MKBYTEARRAY(pAdapterInfo->Address, 6);
+	    ipAddress = __MKSTRING(pAdapterInfo->IpAddressList.IpAddress.String);
+	    ipAddressMask = __MKSTRING(pAdapterInfo->IpAddressList.IpMask.String);
+	    entry = __ARRAY_NEW_INT(5);
+/*
+ * back to ST/X's String definition
+ */
+# ifdef __DEF_String
+#  define String __DEF_String
+# endif
+	    __ArrayInstPtr(entry)->a_element[0] = name; __STORE(entry, name);
+	    __ArrayInstPtr(entry)->a_element[1] = description; __STORE(entry, description);
+	    __ArrayInstPtr(entry)->a_element[2] = macAddress; __STORE(entry, macAddress);
+	    __ArrayInstPtr(entry)->a_element[3] = ipAddress; __STORE(entry, ipAddress);
+	    __ArrayInstPtr(entry)->a_element[4] = ipAddressMask; __STORE(entry, ipAddressMask);
+
+	    __ArrayInstPtr(rawData)->a_element[nA] = entry; __STORE(rawData, entry);
 	    nA++;
-	    bcopy(pAdapterInfo->Address, bP, 6);
-	    bP += 6;
-	    // PrintMACaddress(pAdapterInfo->Address);
 	    pAdapterInfo = pAdapterInfo->Next;
 	} while(pAdapterInfo);
 	nAdapters = __mkSmallInteger(nA);
@@ -5548,7 +5572,21 @@
     nAdapters isNil ifTrue:[
 	self primitiveFailed.
     ].
-    self halt.
+
+    info := Dictionary new.
+    1 to:nAdapters do:[:i |
+	|entry name macAddr|
+
+	entry := rawData at:i.
+	name := entry at:1.
+	macAddr := entry at:3.
+	info at:name put:macAddr.
+    ].
+    ^ info
+
+    "
+     OperatingSystem getNetworkMACAddresses
+    "
 !
 
 getProcessId
@@ -6357,16 +6395,16 @@
       'NON'     'no_NO'
       'NOR'     'no_NO'
      ) pairWiseDo:[:key :mappedValue|
-        key = windowsLanguageString ifTrue:[
-            ^ mappedValue
-        ]
+	key = windowsLanguageString ifTrue:[
+	    ^ mappedValue
+	]
     ].
 
     "no mapping"
     ^ windowsLanguageString.
 
     "
-        self mapLanguage:'DEU'
+	self mapLanguage:'DEU'
     "
 !
 
@@ -6840,31 +6878,31 @@
     wDay = __MKSMALLINT(tmPtr->tm_wday == 0 ? 7 : tmPtr->tm_wday);
 
     if (tmPtr->tm_isdst == 0) {
-        dst = false;
-        utcOffset = __MKINT(TIMEZONE(tmPtr));
+	dst = false;
+	utcOffset = __MKINT(TIMEZONE(tmPtr));
     } else {
-        dst = true;
+	dst = true;
 #ifdef HAS_ALTZONE
-        utcOffset = __MKINT(altzone);
+	utcOffset = __MKINT(altzone);
 #else
-        utcOffset = __MKINT(TIMEZONE(tmPtr) + 3600);
+	utcOffset = __MKINT(TIMEZONE(tmPtr) + 3600);
 #endif
     }
 %}.
     info := self timeInfoClass new.
 
     info
-        year:year
-        month:month
-        day:day
-        hours:hours
-        minutes:minutes
-        seconds:seconds
-        milliseconds:osMilliSeconds
-        utcOffset:utcOffset
-        dst:dst
-        dayInYear:yDay
-        dayInWeek:wDay.
+	year:year
+	month:month
+	day:day
+	hours:hours
+	minutes:minutes
+	seconds:seconds
+	milliseconds:osMilliSeconds
+	utcOffset:utcOffset
+	dst:dst
+	dayInYear:yDay
+	dayInWeek:wDay.
     ^ info
 
     "
@@ -7247,21 +7285,21 @@
 	if (! __isArray(readFdArray)) goto fail;
 	readCount = __arraySize(readFdArray);
     } else {
-        readCount = 0;
+	readCount = 0;
     }
 
     if (__isNonNilObject(writeFdArray)) {
 	if (! __isArray(writeFdArray)) goto fail;
 	writeCount = __arraySize(writeFdArray);
     } else {
-        writeCount = 0;
+	writeCount = 0;
     }
     
     if (__isNonNilObject(exceptFdArray)) {
 	if (! __isArray(exceptFdArray)) goto fail;
 	exceptCount = __arraySize(exceptFdArray);
     } else {
-        exceptCount = 0;
+	exceptCount = 0;
     }
 
     for (i = 0; (i < readCount) && (numHandles < MAXHANDLE);i++) {
@@ -7269,25 +7307,25 @@
 
 	if (fd != nil) {
 	    if (__isExternalAddressLike(fd)) {
-	        hArray  [numHandles] = _HANDLEVal(fd);
-                retArray[numHandles] = i;
-                ++numHandles;
-            } else {
-                if (_canReadWithoutBlocking (__intVal(fd) ) ) {
-                    RETURN (fd);
+		hArray  [numHandles] = _HANDLEVal(fd);
+		retArray[numHandles] = i;
+		++numHandles;
+	    } else {
+		if (_canReadWithoutBlocking (__intVal(fd) ) ) {
+		    RETURN (fd);
 		}
-            }
+	    }
 	}
     }
 
     for (i = 0; (i < writeCount) && (numHandles < MAXHANDLE);i++) {
 	fd = __ArrayInstPtr(writeFdArray)->a_element[i];
 
-        if (fd != nil) {
-            if (__isExternalAddressLike(fd)) {
+	if (fd != nil) {
+	    if (__isExternalAddressLike(fd)) {
 		hArray  [numHandles] = _HANDLEVal(fd);
-                retArray[numHandles] = i + 10000;
-                ++numHandles;
+		retArray[numHandles] = i + 10000;
+		++numHandles;
 	    } else {
 		if (_canWriteWithoutBlocking (__intVal(fd) ) ) {
 		    RETURN (fd);
@@ -7299,11 +7337,11 @@
     for (i = 0; (i < exceptCount) && (numHandles < MAXHANDLE);i++) {
 	fd = __ArrayInstPtr(exceptFdArray)->a_element[i];
 
-        if (fd != nil) {
-            if (__isExternalAddressLike(fd)) {
+	if (fd != nil) {
+	    if (__isExternalAddressLike(fd)) {
 		hArray  [numHandles] = _HANDLEVal(fd);
-                retArray[numHandles] = i + 20000;
-                ++numHandles;
+		retArray[numHandles] = i + 20000;
+		++numHandles;
 	    }
 	}
     }
@@ -7388,19 +7426,19 @@
 	    if (fd != nil) {
 		if (! __isExternalAddressLike(fd)) {
 		    if (_canReadWithoutBlocking (__intVal(fd)) ) {
-                        RETURN (fd);
+			RETURN (fd);
 		    }
 		}
 	    }
 	}
 
-        for (i=0; i < writeCount;i++) {
+	for (i=0; i < writeCount;i++) {
 	    fd = __ArrayInstPtr(writeFdArray)->a_element[i];
 
 	    if (fd != nil) {
 		if (! __isExternalAddressLike(fd)) {
 		    if (_canWriteWithoutBlocking (__intVal(fd)) ) {
-                        RETURN (fd);
+			RETURN (fd);
 		    }
 		}
 	    }
@@ -8163,11 +8201,11 @@
 
     idx := aKeyNamePath indexOf:(self separator).
     idx == 0 ifTrue:[
-        first := aKeyNamePath.
-        rest := nil.
+	first := aKeyNamePath.
+	rest := nil.
     ] ifFalse:[
-        first := aKeyNamePath copyTo:idx-1.
-        rest := aKeyNamePath copyFrom:idx+1
+	first := aKeyNamePath copyTo:idx-1.
+	rest := aKeyNamePath copyFrom:idx+1
     ].
 
     first := first asUppercase.
@@ -8175,11 +8213,11 @@
     "/ the first is a pseudo name
     root := self rootKey:first.
     root isNil ifTrue:[
-        ^ nil
+	^ nil
     ].
 
     rest size == 0 ifTrue:[
-        ^ root
+	^ root
     ].
 
     ^ root subKeyNamed:rest.
@@ -8942,7 +8980,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.141 2004-01-12 09:24:15 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.142 2004-01-26 16:07:57 ca Exp $'
 ! !
 
 !Win32OperatingSystem::Win32FILEHandle methodsFor:'release'!
@@ -8969,7 +9007,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.141 2004-01-12 09:24:15 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.142 2004-01-26 16:07:57 ca Exp $'
 ! !
 
 !Win32OperatingSystem::Win32Handle methodsFor:'io'!
@@ -9356,7 +9394,7 @@
 !Win32OperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.141 2004-01-12 09:24:15 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.142 2004-01-26 16:07:57 ca Exp $'
 ! !
 
 Win32OperatingSystem initialize!