2
0

client.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*************************************************************************
  2. *
  3. * Copyright (C) 2018-2024 Ruilin Peng (Nick) <[email protected]>.
  4. *
  5. * smartdns is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * smartdns is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef _SMARTDNS_CLIENT_
  19. #define _SMARTDNS_CLIENT_
  20. #include <string>
  21. #include <unistd.h>
  22. #include <vector>
  23. namespace smartdns
  24. {
  25. class DNSRecord
  26. {
  27. public:
  28. DNSRecord();
  29. virtual ~DNSRecord();
  30. bool Parser(const std::string &line);
  31. std::string GetName();
  32. std::string GetType();
  33. std::string GetClass();
  34. int GetTTL();
  35. std::string GetData();
  36. private:
  37. std::string name_;
  38. std::string type_;
  39. std::string class_;
  40. int ttl_;
  41. std::string data_;
  42. };
  43. class Client
  44. {
  45. public:
  46. Client();
  47. virtual ~Client();
  48. bool Query(const std::string &dig_cmds, int port = 0, const std::string &ip = "");
  49. std::string GetResult();
  50. std::vector<DNSRecord> GetQuery();
  51. std::vector<DNSRecord> GetAnswer();
  52. std::vector<DNSRecord> GetAuthority();
  53. std::vector<DNSRecord> GetAdditional();
  54. std::vector<std::string> GetOpt();
  55. int GetAnswerNum();
  56. int GetAuthorityNum();
  57. std::string GetStatus();
  58. std::string GetServer();
  59. int GetQueryTime();
  60. int GetMsgSize();
  61. std::string GetFlags();
  62. void Clear();
  63. void PrintResult();
  64. private:
  65. bool ParserResult();
  66. bool ParserRecord(const std::string &record_str, std::vector<DNSRecord> &record);
  67. std::string result_;
  68. int answer_num_{0};
  69. int authority_num_{0};
  70. std::string status_;
  71. std::string server_;
  72. int query_time_{0};
  73. int msg_size_{0};
  74. std::string flags_;
  75. std::vector<DNSRecord> records_query_;
  76. std::vector<DNSRecord> records_answer_;
  77. std::vector<DNSRecord> records_authority_;
  78. std::vector<DNSRecord> records_additional_;
  79. std::vector<std::string> records_opt_;
  80. };
  81. } // namespace smartdns
  82. #endif // _SMARTDNS_CLIENT_