From dc966782b5cf59559944c4bb8fa595180853a0fd Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 1 Jul 2023 14:39:27 +0200 Subject: [PATCH] randomize MACs --- gui/src/main.cpp | 4 +++- netsim/include/Device.hpp | 11 ++++++++++- netsim/src/Device.cpp | 5 +++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/gui/src/main.cpp b/gui/src/main.cpp index e17a6ae..43c1c12 100644 --- a/gui/src/main.cpp +++ b/gui/src/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "imgui.h" @@ -9,6 +10,7 @@ #include "NetworkRenderer.hpp" int main(int argc, char** argv) { + srand(time(NULL)); SDL_Init(SDL_INIT_VIDEO); SDL_Window* window; @@ -64,7 +66,7 @@ int main(int argc, char** argv) { if (ImGui::BeginMenu("New...")) { if (ImGui::MenuItem("Host")) { - auto device = Device::create("12:34:56:78:9A:BC"); + auto device = Device::create(); network.addDevice(device); networkRenderer.AddDevice(device, 400, 400); diff --git a/netsim/include/Device.hpp b/netsim/include/Device.hpp index c31929d..096141e 100644 --- a/netsim/include/Device.hpp +++ b/netsim/include/Device.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -10,7 +11,15 @@ public: public: Device(const std::string& macAddress); - static std::shared_ptr create(const std::string& macAddress); + Device(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f); + + inline static std::shared_ptr create(const std::string& macAddress) { + return std::make_shared(macAddress); + } + + inline static std::shared_ptr create() { + return std::make_shared(rand() % 256, rand() % 256, rand() % 256, rand() % 256, rand() % 256, rand() % 256); + } private: void parseAndSetMac(const std::string& macAddress); diff --git a/netsim/src/Device.cpp b/netsim/src/Device.cpp index 0b3e12e..fbfdf36 100644 --- a/netsim/src/Device.cpp +++ b/netsim/src/Device.cpp @@ -7,8 +7,9 @@ Device::Device(const std::string& macAddress) { parseAndSetMac(macAddress); } -std::shared_ptr Device::create(const std::string& macAddress) { - return std::make_shared(macAddress); +Device::Device(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f) : + macAddress{a, b, c, d, e, f} +{ } void Device::parseAndSetMac(const std::string& mac) {