BOOL CNetworkAdapterList::SetIpAddrEntry(LPCTSTR lpstrMAC, LPCTSTR lpstrIPAddr, LPCTSTR lpstrIPNetMask , LPCTSTR lpstrGateway, LPCTSTR lpstrDhcpServer, LPCTSTR lpstrNetNumber) { CNetworkAdapter cAdapter; POSITION pPosCur, pPosNext; pPosNext = GetHeadPosition(); pPosCur = GetHeadPosition(); while (pPosNext != NULL) { cAdapter = GetNext( pPosNext); if (_tcscmp( cAdapter.GetMACAddress(), lpstrMAC) ==0) { // That's the adapter to update cAdapter.SetIPAddress( lpstrIPAddr); cAdapter.SetIPNetMask( lpstrIPNetMask); cAdapter.SetGateway( lpstrGateway); cAdapter.SetDhcpServer( lpstrDhcpServer); cAdapter.SetNetNumber( lpstrNetNumber ); SetAt( pPosCur, cAdapter); return TRUE; } // Browse the next adapter and save the adapter position in the list pPosCur = pPosNext; } return FALSE; }
/* Concatenate MAC adresses in a CString and return it */ CString CDeviceid::getMacs() { CSysInfo cSysinfo; CNetworkAdapter cObject; CNetworkAdapterList cNetworkAdapterList; POSITION position; BOOL bContinue; CString csMacConcat; m_csMacConcat.Empty(); if (!CIPHelper::GetNetworkAdaptersJustMAC(&cNetworkAdapterList)) return m_csMacConcat; position = cNetworkAdapterList.GetHeadPosition(); bContinue = (position != NULL); if (bContinue) cObject = cNetworkAdapterList.GetNext(position); while (bContinue) { bContinue = (position != NULL); csMacConcat += cObject.GetMACAddress(); if (position != NULL) cObject = cNetworkAdapterList.GetNext( position ); } m_csMacConcat = csMacConcat; return m_csMacConcat; }
LPCTSTR CNetworkAdapterList::GetHash() { COcsCrypto myHash; CNetworkAdapter myObject; POSITION pos; BOOL bContinue; CString csToHash; if (GetCount() == 0) return NULL; if (!myHash.HashInit()) return NULL; pos = GetHeadPosition(); bContinue = (pos != NULL); if (bContinue) // There is one record => get the first myObject = GetNext( pos); while (bContinue) { csToHash.Format( _T( "%s%s%s%s%s%s%s%s%s"), myObject.GetDescription(), myObject.GetType(), myObject.GetTypeMIB(), myObject.GetMACAddress(), myObject.GetOperationalStatus(), myObject.GetIPAddress(), myObject.GetIPNetMask(), myObject.GetGateway(), myObject.GetDhcpServer()); myHash.HashUpdate( csToHash); bContinue = (pos != NULL); if (bContinue) myObject = GetNext( pos); } return myHash.HashFinal(); }
int CNetworkAdapter::operator==(CNetworkAdapter cObject) const { return ((m_csNetNumber == cObject.GetNetNumber()) && (m_lIndex == cObject.GetIfIndex()) && (m_csDescription == cObject.GetDescription()) && (m_csType == cObject.GetType()) && (m_csTypeMIB == cObject.GetTypeMIB()) && (m_csSpeed == cObject.GetSpeed()) && (m_ulSpeed == cObject.GetByteSpeed()) && (m_csHWAddr == cObject.GetMACAddress()) && (m_csOperStatus == cObject.GetOperationalStatus()) && (m_csIPAddr == cObject.GetIPAddress()) && (m_csIPNetMask == cObject.GetIPNetMask()) && (m_csGateway == cObject.GetGateway()) && (m_csDhcpServer == cObject.GetDhcpServer())); }