diff --git a/source/gns3/GnsNode.cpp b/source/gns3/GnsNode.cpp index 58f8f8d..f12bb33 100644 --- a/source/gns3/GnsNode.cpp +++ b/source/gns3/GnsNode.cpp @@ -9,14 +9,14 @@ namespace gns { -GnsNode::GnsNode(const GnsProject *project, std::string uuid, const std::vector& ports) { +GnsNode::GnsNode(const GnsProject *project, const std::string& uuid, const std::vector& ports) { this->project = project; - this->uuid = std::move(uuid); + this->uuid = uuid; this->ports = ports; } std::string GnsNode::getApiBase() const { - return this->project->getApiBase() + "nodes/" + this->uuid + "/"; + return this->project->getApiBase() + "nodes/" + this->getUuid() + "/"; } std::string GnsNode::getUuid() const { @@ -30,7 +30,7 @@ std::vector GnsNode::getPorts() const { void GnsNode::start() const { // request the API endpoint cpr::Url endpoint = this->getApiBase() + "start"; - cpr::Response response = Post(endpoint); + const cpr::Response response = Post(endpoint); // check for a valid response if (response.error.code != cpr::ErrorCode::OK) diff --git a/source/gns3/GnsNode.hpp b/source/gns3/GnsNode.hpp index d6303a5..68a75d0 100644 --- a/source/gns3/GnsNode.hpp +++ b/source/gns3/GnsNode.hpp @@ -18,7 +18,7 @@ class GnsProject; */ class GnsNode { public: - GnsNode(const GnsProject* project, std::string uuid, const std::vector& ports); + GnsNode(const GnsProject* project, const std::string& uuid, const std::vector& ports); /** * Get the base URL for the node API diff --git a/source/gns3/GnsProject.cpp b/source/gns3/GnsProject.cpp index dec21b7..851390e 100644 --- a/source/gns3/GnsProject.cpp +++ b/source/gns3/GnsProject.cpp @@ -10,13 +10,13 @@ using json = nlohmann::json; namespace gns { -GnsProject::GnsProject(const GnsServer* server, std::string uuid) { +GnsProject::GnsProject(const GnsServer* server, const std::string& uuid) { this->server = server; - this->uuid = std::move(uuid); + this->uuid = uuid; } std::string GnsProject::getApiBase() const { - return this->server->getApiBase() + "projects/" + this->uuid + "/"; + return this->server->getApiBase() + "projects/" + this->getUuid() + "/"; } std::string GnsProject::getUuid() const { diff --git a/source/gns3/GnsProject.hpp b/source/gns3/GnsProject.hpp index 9f67922..3c1c383 100644 --- a/source/gns3/GnsProject.hpp +++ b/source/gns3/GnsProject.hpp @@ -16,7 +16,7 @@ class GnsServer; */ class GnsProject { public: - GnsProject(const GnsServer* server, std::string uuid); + GnsProject(const GnsServer* server, const std::string& uuid); /** * Get the base prefix for an API request diff --git a/source/gns3/GnsServer.cpp b/source/gns3/GnsServer.cpp index 566a729..43ad603 100644 --- a/source/gns3/GnsServer.cpp +++ b/source/gns3/GnsServer.cpp @@ -8,7 +8,7 @@ using json = nlohmann::json; namespace gns { -GnsServer::GnsServer(const std::string &host, const std::uint16_t port) { +GnsServer::GnsServer(const std::string& host, const std::uint16_t port) { this->host = host; this->port = port; } diff --git a/source/main.cpp b/source/main.cpp index 600b5d9..cda5028 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -14,6 +14,10 @@ #include "utils/address.hpp" + +std::shared_ptr gnsServer; + + /** * Callback of a detected Wake-On-LAN packet */ @@ -22,8 +26,6 @@ void packet_wol_handler( const pcap_pkthdr* header, const std::uint8_t* packet ) { - const auto server = reinterpret_cast(user_data); - // get the special sll header (added by pcap when using the "any" device) std::uint16_t sll_header = *packet; // get the ethernet header of the packet @@ -48,7 +50,7 @@ void packet_wol_handler( // TODO(Faraphel): check the 16 repetitions of the source address ? // find the machine with the mac address - for (const gns::GnsNode& node : server->getNodes()) + for (const gns::GnsNode& node : gnsServer->getNodes()) for (const gns::GnsPort& port : node.getPorts()) if (port.mac_address == mac_address_target) { std::cout << "Matching node: " + node.getUuid() << std::endl; @@ -62,7 +64,7 @@ void packet_wol_handler( int main() { // get the GNS3 server - auto server = gns::GnsServer("localhost", 80); + gnsServer = std::make_shared("localhost", 80); // capture any packet on the selected interface char error_buffer[PCAP_ERRBUF_SIZE]; @@ -89,7 +91,7 @@ int main() { handle.get(), 0, packet_wol_handler, - reinterpret_cast(&server) + nullptr ) == -1) throw std::runtime_error("pcap_loop() failed: " + std::string(error_buffer));