randomize MACs

This commit is contained in:
Robert 2023-07-01 14:39:27 +02:00
parent c295b13018
commit dc966782b5
3 changed files with 16 additions and 4 deletions

View file

@ -1,4 +1,5 @@
#include <iostream> #include <iostream>
#include <random>
#include <SDL.h> #include <SDL.h>
#include "imgui.h" #include "imgui.h"
@ -9,6 +10,7 @@
#include "NetworkRenderer.hpp" #include "NetworkRenderer.hpp"
int main(int argc, char** argv) { int main(int argc, char** argv) {
srand(time(NULL));
SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window; SDL_Window* window;
@ -64,7 +66,7 @@ int main(int argc, char** argv) {
if (ImGui::BeginMenu("New...")) { if (ImGui::BeginMenu("New...")) {
if (ImGui::MenuItem("Host")) { if (ImGui::MenuItem("Host")) {
auto device = Device::create("12:34:56:78:9A:BC"); auto device = Device::create();
network.addDevice(device); network.addDevice(device);
networkRenderer.AddDevice(device, 400, 400); networkRenderer.AddDevice(device, 400, 400);

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <array>
#include <string> #include <string>
#include <memory> #include <memory>
@ -10,7 +11,15 @@ public:
public: public:
Device(const std::string& macAddress); Device(const std::string& macAddress);
static std::shared_ptr<Device> 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<Device> create(const std::string& macAddress) {
return std::make_shared<Device>(macAddress);
}
inline static std::shared_ptr<Device> create() {
return std::make_shared<Device>(rand() % 256, rand() % 256, rand() % 256, rand() % 256, rand() % 256, rand() % 256);
}
private: private:
void parseAndSetMac(const std::string& macAddress); void parseAndSetMac(const std::string& macAddress);

View file

@ -7,8 +7,9 @@ Device::Device(const std::string& macAddress) {
parseAndSetMac(macAddress); parseAndSetMac(macAddress);
} }
std::shared_ptr<Device> Device::create(const std::string& macAddress) { Device::Device(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f) :
return std::make_shared<Device>(macAddress); macAddress{a, b, c, d, e, f}
{
} }
void Device::parseAndSetMac(const std::string& mac) { void Device::parseAndSetMac(const std::string& mac) {