#include "util.h" #include "inet4d.h" ///////////////////////////////////////////////////////////////////////////// bool ParseIfaceInet4dParam(const std::vector &v, IFACE_INET_DHCP &id) { auto vSize = v.size(); if(vSize >= 2) { if(!v[0].compare("hostname")) { id.hostname = v[1]; return true; } else if(!v[0].compare("metric") && IsDecimalInt(v[1].c_str())) { id.metric = (int)std::stol(v[1], 0, 0); return true; } else if(!v[0].compare("leasehours") && IsDecimalInt(v[1].c_str())) { id.leasehours = (int)std::stol(v[1], 0, 0); return true; } else if(!v[0].compare("leasetime") && IsDecimalInt(v[1].c_str())) { id.leasetime = (int)std::stol(v[1], 0, 0); return true; } else if(!v[0].compare("vendor")) { id.vendor = v[1]; return true; } else if(!v[0].compare("client")) { id.client = v[1]; return true; } else if(!v[0].compare("hwaddress")) { id.hwaddr = v[1]; strlcase(id.hwaddr); return true; } } return false; } ///////////////////////////////////////////////////////////////////////////// bool WriteIfaceInet4dParam(FILE *pf, const IFACE_INET_DHCP &id) { if(!id.hostname.empty()) { fprintf(pf, "\thostname %s\n", id.hostname.c_str()); } if(id.metric >= 0) { fprintf(pf, "\tmetric %d\n", id.metric); } if(id.leasehours > 0) { fprintf(pf, "\tleasehours %d\n", id.leasehours); } if(id.leasetime > 0) { fprintf(pf, "\tleasetime %d\n", id.leasetime); } if(!id.vendor.empty()) { fprintf(pf, "\tvendor %s\n", id.vendor.c_str()); } if(!id.client.empty()) { fprintf(pf, "\tclient %s\n", id.client.c_str()); } if(!id.hwaddr.empty()) { fprintf(pf, "\thwaddress %s\n", id.hwaddr.c_str()); } return true; }