-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: MAC Address #106
Comments
Not here, maybe it makes sense in SDL_net? |
I don’t know if I’ll add this yet, but I’ve moved this to SDL_net and reopened it for now. |
Here is a pass at Windows version, putting it here instead of filing a PR since it's not clear if it belongs in SDL: #include <Windows.h>
#include <iphlpapi.h>
#pragma comment(lib, "Iphlpapi.lib")
#include <Shlwapi.h>
#pragma comment(lib, "Shlwapi.lib")
// Parameter is an array of size 6
bool macGetFromArbitraryNIC (unsigned char mac[])
{
static bool is_cached = false;
static unsigned char mac_cached[6];
if (!is_cached) {
IP_ADAPTER_INFO adapters[64]; // Maximum number of adapters we want to iterate over
DWORD adapters_size = sizeof(adapters);
DWORD status = GetAdaptersInfo(adapters, &adapters_size);
if (status == ERROR_SUCCESS) {
PIP_ADAPTER_INFO adapt = &adapters[0];
do {
if (((adapt->Type == MIB_IF_TYPE_ETHERNET) ||
(adapt->Type == IF_TYPE_IEEE80211)) &&
!StrStrIA(adapt->Description, "virtual")) {
CopyMemory(mac, adapt->Address, 6);
CopyMemory(mac_cached, adapt->Address, 6);
is_cached = true;
return true; // If MAC found
}
adapt = adapt->Next;
} while (adapt);
return false; // If no valid MAC found
} else {
return false; // If couldn't get information about NICs
}
} else {
CopyMemory(mac, mac_cached, 6);
return true; // If MAC is already cached
}
} Different runs of the application may return different MACs (due to NICs appearing in different order), but fixing that will require too much overhead. Also, we filter out address for virtual NICs since they may be same on different machines. |
Would there be interest in adding a function to get the MAC address of the machine in SDL? This would be useful in calculating UUIDv1. I could contribute the Windows version, but wanted to know if it is desired (and if yes, should it go here or in SDL_net).
The text was updated successfully, but these errors were encountered: