mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-03-12 06:39:14 +01:00
Common: Use C++ random generator for generating MAC addresses
This commit is contained in:
parent
98e5270b3c
commit
a870253cd6
@ -3,12 +3,13 @@
|
|||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
#include "Common/Network.h"
|
#include "Common/Network.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
|
#include "Common/Timer.h"
|
||||||
|
|
||||||
void GenerateMacAddress(const MACConsumer type, u8* mac)
|
void GenerateMacAddress(const MACConsumer type, u8* mac)
|
||||||
{
|
{
|
||||||
@ -27,16 +28,12 @@ void GenerateMacAddress(const MACConsumer type, u8* mac)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
srand((unsigned int)time(nullptr));
|
// Generate the 24-bit NIC-specific portion of the MAC address.
|
||||||
|
std::default_random_engine generator(Common::Timer::GetTimeMs());
|
||||||
u8 id[3] =
|
std::uniform_int_distribution<int> distribution(0x00, 0xFF);
|
||||||
{
|
mac[3] = static_cast<u8>(distribution(generator));
|
||||||
(u8)rand(),
|
mac[4] = static_cast<u8>(distribution(generator));
|
||||||
(u8)rand(),
|
mac[5] = static_cast<u8>(distribution(generator));
|
||||||
(u8)rand()
|
|
||||||
};
|
|
||||||
|
|
||||||
memcpy(&mac[3], id, 3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MacAddressToString(const u8* mac)
|
std::string MacAddressToString(const u8* mac)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user