| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include "util.h"
- #include "inet4d.h"
- /////////////////////////////////////////////////////////////////////////////
- bool ParseIfaceInet4dParam(const std::vector<std::string> &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;
- }
|