Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef _WIN32
- namespace win{
- #include <windows.h>
- #include <intrin.h>
- #include <iphlpapi.h>
- #include <stdio.h>
- #include <stdlib.h>
- #pragma comment(lib, "IPHLPAPI.lib")
- // we just need this for purposes of unique machine id. So any one or two mac's is
- // fine.
- unsigned short hashMacAddress( PIP_ADAPTER_INFO info )
- {
- unsigned short hash = 0;
- for ( unsigned int i = 0; i < info->AddressLength; i++ )
- {
- hash += ( info->Address[i] << (( i & 1 ) * 8 ));
- }
- return hash;
- }
- void getMacHash( unsigned short& mac1, unsigned short& mac2 )
- {
- IP_ADAPTER_INFO AdapterInfo[32];
- ULONG dwBufLen = sizeof( AdapterInfo );
- ULONG dwStatus = GetAdaptersInfo( AdapterInfo, &dwBufLen );
- if ( dwStatus != ERROR_SUCCESS )
- return; // no adapters.
- PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
- mac1 = hashMacAddress( pAdapterInfo );
- if ( pAdapterInfo->Next )
- mac2 = hashMacAddress( pAdapterInfo->Next );
- // sort the mac addresses. We don't want to invalidate
- // both macs if they just change order.
- if ( mac1 > mac2 )
- {
- unsigned short tmp = mac2;
- mac2 = mac1;
- mac1 = tmp;
- }
- }
- unsigned short getVolumeHash()
- {
- DWORD serialNum = 0;
- // Determine if this volume uses an NTFS file system.
- GetVolumeInformation( "c:\\", NULL, 0, &serialNum, NULL, NULL, NULL, 0 );
- unsigned short hash = (unsigned short)(( serialNum + ( serialNum >> 16 )) & 0xFFFF );
- return hash;
- }
- unsigned short getCpuHash()
- {
- int cpuinfo[4] = { 0, 0, 0, 0 };
- __cpuid( cpuinfo, 0 );
- unsigned short hash = 0;
- unsigned short* ptr = (unsigned short*)(&cpuinfo[0]);
- for ( unsigned int i = 0; i < 8; i++ )
- hash += ptr[i];
- return hash;
- }
- const char* getMachineName()
- {
- static char computerName[1024];
- DWORD size = 1024;
- GetComputerName( computerName, &size );
- return &(computerName[0]);
- }
- }
- #endif//_WIN32
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement