/* * ethernet.cpp * * Created on: Jan 11, 2020 * Author: devel */ #include #include #include #include #include "../base/base.h" #include "../os/network.hpp" #include "pc_identifier.hpp" #include "ethernet.hpp" namespace license { namespace pc_identifier { using namespace std; static FUNCTION_RETURN generate_ethernet_pc_id(vector> &data, const bool use_ip) { vector adapters; FUNCTION_RETURN result_adapterInfos = getAdapterInfos(adapters); if (result_adapterInfos != FUNC_RET_OK) { return result_adapterInfos; } if (adapters.size() == 0) { return FUNC_RET_NOT_AVAIL; } for (auto &it : adapters) { unsigned int k, data_len, data_byte; array identifier; data_len = use_ip ? sizeof(os::OsAdapterInfo::ipv4_address) : sizeof(os::OsAdapterInfo::mac_address); for (k = 0; k < PC_IDENTIFIER_PROPRIETARY_DATA; k++) { if (k < data_len) { identifier[k] = use_ip ? it.ipv4_address[k] : it.mac_address[k]; } else { identifier[k] = 42; } } identifier[0] = identifier[0] & 0x1F; data.push_back(identifier); } return result_adapterInfos; } Ethernet::Ethernet(bool useIp) : use_ip(useIp) {} Ethernet::~Ethernet() {} LCC_API_IDENTIFICATION_STRATEGY Ethernet::identification_strategy() const { return STRATEGY_ETHERNET; } FUNCTION_RETURN Ethernet::identify_pc(PcIdentifier &pc_id) const { vector> data; FUNCTION_RETURN result = generate_ethernet_pc_id(data, use_ip); if (result == FUNC_RET_OK) { pc_id.set_data(data[0]); } return result; } std::vector Ethernet::alternative_ids() const { vector> data; FUNCTION_RETURN result = generate_ethernet_pc_id(data, use_ip); vector identifiers; if (result == FUNC_RET_OK) { identifiers.resize(data.size()); for (auto &it : data) { PcIdentifier pc_id; pc_id.set_identification_strategy(identification_strategy()); pc_id.set_data(it); identifiers.push_back(pc_id); } } return identifiers; } LCC_EVENT_TYPE Ethernet::validate_identifier(const PcIdentifier &identifier) const { vector> data; FUNCTION_RETURN generate_ethernet = generate_ethernet_pc_id(data, use_ip); LCC_EVENT_TYPE result = IDENTIFIERS_MISMATCH; if (generate_ethernet == FUNC_RET_OK) { result = validate_identifier(identifier, data); } return result; } } // namespace pc_identifier } /* namespace license */