Skip to content

pfrrodrigues/wakeonlan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

200 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wakeonlan

A friendly C++ library for managing and ingress on Wake-on-LAN groups.

Minimum Dependencies

  • CMake 3.5.1
  • C++ 14
  • GCC 5.5.0
  • Linux environment supporting the POSIX standard

Cloning Repository and Building the library

$ git clone git@github.com:pfrrodrigues/wakeonlan.git --recurse-submodules
$ cd wakeonlan
$ mkdir build && cd build
$ cmake .. && make -j 2

Optionally, you can set the build type of your preference:

$ cmake -DCMAKE_BUILD_TYPE=Release .. && make

or

$ cmake -DCMAKE_BUILD_TYPE=Debug .. && make

After execute one of the above commands a shared API library will be available on the build directory for use.

Getting started

CMakeLists.txt generates a basic example application (wolapp) for users start exploring the Wake-on-LAN API. In order to run it, one can just execute the application found on the generated build directory.

$ ./wolapp

Example Application

#include <memory>
#include <unistd.h>
#include <csignal>
#include <ApiInstance.hpp>

bool quit = false;

void signalHandler(int signum) {
    quit = true;
}

void terminate() {
    pid_t pid = getpid();
    std::string killCmd("kill ");
    killCmd.append(std::to_string(pid));
    system(killCmd.c_str());
}

int main(int argc, char** argv) {
    signal(SIGINT, signalHandler);
    /*************************************
    * API configuration
    *************************************/
    WakeOnLan::Config config;

    /*************************************
    * API instantiation
    *************************************/
    WakeOnLan::ApiInstance api(config);

    /*************************************
    * Run the API
    *************************************/
    api.run();
    while (!quit) {}
    api.stop();
    terminate();
}

API configuration

In order to start the API, the Config struct is needed. This struct is responsible for internally finds out the local host interface to use for receiving incoming packets and for setting up the device configuration needed to run the service.

WakeOnLan::Config config;

The Config struct provides a set of functions for user checks if the configuration was constructed correctly.

  • getHostname() - Gets the local host hostname.
  • getIface() - Gets the local host interface.
  • getIpAddress() - Gets the local host IP address.
  • getMacAddress() - Gets the local host MAC address.
  • getHandlerType() - Gets the API handler type.

API instantiation

Once a Config object is created users can create a ApiInstance object to instantiate the API.

WakeOnLan::ApiInstance api(config);

Supported interfaces

The API abstracts and encapsulates all the behavior of the services provided by it. To start running the services user must just make a call to run() function. At this point, the API is already listening on port 4000 (service port) for incoming packets and already to respond to the requests messages coming from the services running on other hosts.

api.run();
  • For stop the services one can just call the stop() function.
api.stop();

The API log file

The wakeonlan API provides a log file for users checks the API behavior and main events occurred. The log file is named wakeonlan-api.log and can be found on the log/ folder created inside the directory where the program was executed. On the example, logs/ folder was created inside the build/ directory.

Example:

[15-02-2023 19:37:06] [info] ---------------- Wake on Lan API ---------------
[15-02-2023 19:37:06] [info] Version 1.0.0
[15-02-2023 19:37:06] [info] Handler: Manager
[15-02-2023 19:37:06] [info] Hostname: sisop-2
[15-02-2023 19:37:06] [info] IP Address: 192.168.1.10
[15-02-2023 19:37:06] [info] MAC Address: 00:D5:7D:3C:54:A9
[15-02-2023 19:37:06] [info] Start Network handler
[15-02-2023 19:37:06] [info] Network handler (internal): listening on port 4000
[15-02-2023 19:37:06] [info] Starting handler
[15-02-2023 19:37:06] [info] Start Interface service
[15-02-2023 19:37:06] [info] Start Discovery service
[15-02-2023 19:37:06] [info] STATUS UPDATE: Synchronized
[15-02-2023 19:37:06] [info] Start Monitoring service
[15-02-2023 19:37:08] [info] Network handler (internal): listener socket is closed
[15-02-2023 19:37:09] [info] Stop Network handler
[15-02-2023 19:37:10] [info] Stop Discovery service
[15-02-2023 19:37:10] [info] Stop Monitoring service
[15-02-2023 19:37:10] [info] Stop Interface service
[15-02-2023 19:37:11] [info] Stopping handler

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors