MLOCAL_ID = MacAddress(GETENV("COMPUTERNAME")) MSERVER_ID = MacAddress(MappedDriveServerPath(SYS(5))) ************************************************************************* * MappedDriveServerPath: Used to get the server name of the mapped drive ************************************************************************* FUNCTION MappedDriveServerPath PARAMETERS cLocalDevice DECLARE INTEGER WNetGetConnection IN WIN32API ; STRING @ lpLocalName, ; STRING @ lpRemoteName, ; INTEGER @ lpnLength cUNCBuffer = REPL(CHR(0),261) nLength = LEN(cUNCBuffer) IF WNetGetConnection(cLocalDevice, @cUNCBuffer, @nLength) = 0 PATH = LEFT(cUNCBuffer,AT(CHR(0),cUNCBuffer)-1) && GET PATH PATH = SUBSTR(PATH,3) && REMOVE \\ FROM PATH NAME FIRSTSLASHPOS = ATC("\",PATH) PATH = SUBSTR(PATH,1,((LEN(PATH)-1)-(LEN(PATH)-FIRSTSLASHPOS))) RETURN PATH ELSE RETURN GETENV("COMPUTERNAME") && we are the server so just return our name ENDIF ************************************************************************* * ServerMacAddress: Used to get the server mac address whether * or not we are the client ************************************************************************* FUNCTION MacAddress PARAMETERS cServerName #DEFINE MAX_PREFERRED_LENGTH -1 #DEFINE NERR_Success 0 DO decl LOCAL cServer, cBuffer, hBuffer, nBufsize,; nEntriesRead, nEntriesTotal cBuffer = Repli(Chr(0), 16384) STORE 0 TO hBuffer, nBufsize, nEntriesRead, nEntriesTotal nResult = NetWkstaTransportEnum(cServer, 0, @hBuffer,; MAX_PREFERRED_LENGTH, @nEntriesRead, @nEntriesTotal, 0) IF nResult <> NERR_Success = NetApiBufferFree(hBuffer) RETURN ENDIF * obtain size of the buffer = NetApiBufferSize(hBuffer, @nBufsize) cBuffer = Repli(Chr(0), nBufsize) CopyMemory(@cBuffer, hBuffer, nBufsize) #DEFINE TRANSPORT_INFO_SIZE 20 LOCAL nIndex, hName, hAddress, cName, cAddress, ch, cReturnValue *CREATE CURSOR cs (devname C(70), srvaddress C(50)) * retrieving device names and server address for existing * transport protocols FOR nIndex=1 TO nEntriesRead hName = buf2dword(SUBSTR(cBuffer,; (nIndex-1)*TRANSPORT_INFO_SIZE+9,4)) hAddress = buf2dword(SUBSTR(cBuffer,; (nIndex-1)*TRANSPORT_INFO_SIZE+13,4)) hName = hName - hBuffer && decrease by initial offset cName = "" DO WHILE .T. ch = SUBSTR(cBuffer, hName, 2) IF ch = Chr(0)+Chr(0) Or hName > Len(cBuffer) EXIT ENDIF cName = cName + ch hName = hName + 2 ENDDO cName = STRTRAN(cName, Chr(0), "") hAddress = hAddress - hBuffer && decrease by initial offset cAddress = "" DO WHILE .T. ch = SUBSTR(cBuffer, hAddress, 2) IF ch = Chr(0)+Chr(0) Or hAddress > Len(cBuffer) EXIT ENDIF cAddress = cAddress + ch hAddress = hAddress + 2 ENDDO cAddress = STRTRAN(cAddress, Chr(0), "") *INSERT INTO cs VALUES (cName, cAddress) *CHECK TO SEE IF IT IS A NETBIOS AND SKIP IT (WE WILL GRAB THE LAST NESHOWN) IF !("\Device\NetBiosSmb" $ cName) cReturnValue = cAddress && This is the mac address we will return ENDIF ENDFOR = NetApiBufferFree(hBuffer) RETURN cReturnValue PROCEDURE decl DECLARE INTEGER NetWkstaTransportEnum IN netapi32; STRING servername, LONG lvl, INTEGER @bufptr,; LONG prefmaxlen, LONG @entriesread,; LONG @totalentries, LONG resumehandle DECLARE INTEGER NetApiBufferFree IN netapi32 INTEGER Buffer DECLARE INTEGER NetApiBufferSize IN netapi32; INTEGER Buffer, INTEGER @ByteCount DECLARE RtlMoveMemory IN kernel32 As CopyMemory; STRING @dst, INTEGER src, INTEGER bufsize FUNCTION buf2dword(lcBuffer) RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ; BitLShift(Asc(SUBSTR(lcBuffer, 2,1)), 8) +; BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +; BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)