inet4d.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "util.h"
  2. #include "inet4d.h"
  3. /////////////////////////////////////////////////////////////////////////////
  4. bool ParseIfaceInet4dParam(const std::vector<std::string> &v, IFACE_INET_DHCP &id)
  5. {
  6. auto vSize = v.size();
  7. if(vSize >= 2)
  8. {
  9. if(!v[0].compare("hostname"))
  10. {
  11. id.hostname = v[1];
  12. return true;
  13. }
  14. else if(!v[0].compare("metric") && IsDecimalInt(v[1].c_str()))
  15. {
  16. id.metric = (int)std::stol(v[1], 0, 0);
  17. return true;
  18. }
  19. else if(!v[0].compare("leasehours") && IsDecimalInt(v[1].c_str()))
  20. {
  21. id.leasehours = (int)std::stol(v[1], 0, 0);
  22. return true;
  23. }
  24. else if(!v[0].compare("leasetime") && IsDecimalInt(v[1].c_str()))
  25. {
  26. id.leasetime = (int)std::stol(v[1], 0, 0);
  27. return true;
  28. }
  29. else if(!v[0].compare("vendor"))
  30. {
  31. id.vendor = v[1];
  32. return true;
  33. }
  34. else if(!v[0].compare("client"))
  35. {
  36. id.client = v[1];
  37. return true;
  38. }
  39. else if(!v[0].compare("hwaddress"))
  40. {
  41. id.hwaddr = v[1];
  42. strlcase(id.hwaddr);
  43. return true;
  44. }
  45. }
  46. return false;
  47. }
  48. /////////////////////////////////////////////////////////////////////////////
  49. bool WriteIfaceInet4dParam(FILE *pf, const IFACE_INET_DHCP &id)
  50. {
  51. if(!id.hostname.empty())
  52. {
  53. fprintf(pf, "\thostname %s\n", id.hostname.c_str());
  54. }
  55. if(id.metric >= 0)
  56. {
  57. fprintf(pf, "\tmetric %d\n", id.metric);
  58. }
  59. if(id.leasehours > 0)
  60. {
  61. fprintf(pf, "\tleasehours %d\n", id.leasehours);
  62. }
  63. if(id.leasetime > 0)
  64. {
  65. fprintf(pf, "\tleasetime %d\n", id.leasetime);
  66. }
  67. if(!id.vendor.empty())
  68. {
  69. fprintf(pf, "\tvendor %s\n", id.vendor.c_str());
  70. }
  71. if(!id.client.empty())
  72. {
  73. fprintf(pf, "\tclient %s\n", id.client.c_str());
  74. }
  75. if(!id.hwaddr.empty())
  76. {
  77. fprintf(pf, "\thwaddress %s\n", id.hwaddr.c_str());
  78. }
  79. return true;
  80. }