#pragma once
template <class T>
class single_instance {
public:
static inline T instance() {
static T obj;
return obj;
}
private:
single_instance() = default;
virtual ~single_instance() = default;
};
#pragma once
#include <stdio.h>
#include "single_instance.hpp"
class net_utility {
public:
void get_mac_str(unsigned long mac_val, std::string &mac_str) {
static const char *convert_format = "%02x:%02x:%02x:%02x:%02x:%02x";
char buf[24] = "";
snprintf(buf, sizeof(buf), convert_format, (mac_val >> 40) & 0xff,
(mac_val >> 32) & 0xff,
(mac_val >> 24) & 0xff,
(mac_val >> 16) & 0xff,
(mac_val >> 8) & 0xff,
mac_val & 0xff);
mac_str = buf;
}
};
#define G_NET_UTILITY single_instance<net_utility>::instance()
#include "net_utility.hpp"
#include <iostream>
int main() {
std::string mac_str;
G_NET_UTILITY.get_mac_str(1, mac_str);
std::cout << mac_str << std::endl;
return 0;
}