From c4ced7a835744e4dbeec632a8c7c818af3e3d7b9 Mon Sep 17 00:00:00 2001 From: GreenBagels <1337greenbagels@gmail.com> Date: Thu, 19 Jun 2014 15:38:54 -0400 Subject: [PATCH] Forward Declaration of OnRandomMACAddress added. Added function to create random MAC ...added headers needed for CreateRandMAC Defined function to create a random MAC Added in option to randomize MAC address Changed uint_16 to u16 from CommonTypes.h Fixed case sensitivity. Woo! QT -= gui caused to not be found undo unnecessary change undo the undo removed random option, fixed spacing removed forward declaration Changed default mac to random one Added in several STL includes: iostream, sstream. CreateRandMAC is now only used for initial runs, no more random option. Removed unneeded headers Moved ctime and cstdlib to the cpp file Added in random MAC function call Update Config.cpp Revert "undo the undo" This reverts commit e21852961806727230dca31ceb5193ee2f298c7b. --- Core/Config.cpp | 18 +++++++++++++++++- Core/Config.h | 4 +++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index b3422d79d4..36aa8e6ad1 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -15,6 +15,9 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include +#include + #include "base/display.h" #include "base/NativeApp.h" #include "ext/vjson/json.h" @@ -530,7 +533,7 @@ static ConfigSetting systemParamSettings[] = { ReportedConfigSetting("PSPFirmwareVersion", &g_Config.iFirmwareVersion, PSP_DEFAULT_FIRMWARE), ConfigSetting("NickName", &g_Config.sNickName, "PPSSPP"), ConfigSetting("proAdhocServer", &g_Config.proAdhocServer, "localhost"), - ConfigSetting("MacAddress", &g_Config.localMacAddress, "01:02:03:04:05:06"), + ConfigSetting("MacAddress", &g_Config.localMacAddress, g_Config.CreateRandMAC().c_str()), ReportedConfigSetting("Language", &g_Config.iLanguage, &DefaultSystemParamLanguage), ConfigSetting("TimeFormat", &g_Config.iTimeFormat, PSP_SYSTEMPARAM_TIME_FORMAT_24HR), ConfigSetting("DateFormat", &g_Config.iDateFormat, PSP_SYSTEMPARAM_DATE_FORMAT_YYYYMMDD), @@ -997,3 +1000,16 @@ void Config::GetReportingInfo(UrlEncoder &data) { } } } + +std::string Config::CreateRandMAC() { + std::stringstream randStream; + srand(time(0)); + for(int i = 0; i < 6; i++) { + randStream << std::hex << (rand() % 256); //generates each octet for the mac in hex format + if (i<5) { + randStream << ':'; //we need a : between every octet + } + } + return randStream.str(); //no need for creating a new string, just return this +} + diff --git a/Core/Config.h b/Core/Config.h index 254b5cac0b..09ccb450fe 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -336,7 +336,9 @@ public: void ResetControlLayout(); void GetReportingInfo(UrlEncoder &data); - + + std::string CreateRandMAC(); // Uses 's rand() PRNG to create a pseudorandom MAC address + private: std::string iniFilename_; std::string controllerIniFilename_;