updated minor memory management to avoid text corruption
This commit is contained in:
parent
4e547635d8
commit
9c413c0edd
6 changed files with 17 additions and 15 deletions
|
@ -14,6 +14,10 @@
|
|||
#include "utils/address.hpp"
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<gns::GnsServer> 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<gns::GnsServer*>(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<gns::GnsServer>("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<uint8_t*>(&server)
|
||||
nullptr
|
||||
) == -1)
|
||||
throw std::runtime_error("pcap_loop() failed: " + std::string(error_buffer));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue