You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.6 KiB

7 years ago
​
​
​
7 years ago
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
  1. #ifndef UPNPNAT_H
  2. #define UPNPNAT_H
  3. #include "../../components/base/basicLogCollection.h"
  4. #include <string>
  5. #include <vector>
  6. #pragma warning(disable : 4251)
  7. #define DefaultTimeOut 10
  8. #define DefaultInterval 200
  9. class /*__declspec (dllexport)*/ UPNPNAT
  10. {
  11. public:
  12. UPNPNAT();
  13. ~UPNPNAT();
  14. bool init(int time_out = DefaultTimeOut, int interval = DefaultInterval); // init
  15. bool discovery(); // find router
  16. /****
  17. **** _description: port mapping name
  18. **** _destination_ip: internal ip address
  19. **** _port_ex:external: external listen port
  20. **** _destination_port: internal port
  21. **** _protocal: TCP or UDP
  22. ***/
  23. bool add_port_mapping(char * _description, char * _destination_ip, unsigned short int _port_ex, unsigned short int _destination_port, char * _protocal); // add port mapping
  24. const char * get_last_error()
  25. {
  26. return last_error.c_str();
  27. } // get last error
  28. private:
  29. basicLogCollection * m_pLog;
  30. bool get_description(); //
  31. bool parser_description(); //
  32. bool tcp_connect(const char * _addr, unsigned short int _port);
  33. bool parse_mapping_info();
  34. int udp_socket_fd;
  35. int tcp_socket_fd;
  36. typedef enum
  37. {
  38. NAT_INIT = 0,
  39. NAT_FOUND,
  40. NAT_TCP_CONNECTED,
  41. NAT_GETDESCRIPTION,
  42. NAT_GETCONTROL,
  43. NAT_ADD,
  44. NAT_DEL,
  45. NAT_GET,
  46. NAT_ERROR
  47. } NAT_STAT;
  48. NAT_STAT status;
  49. int time_out;
  50. int interval;
  51. std::string service_type;
  52. std::string describe_url;
  53. std::string control_url;
  54. std::string base_url;
  55. std::string service_describe_url;
  56. std::string description_info;
  57. std::string last_error;
  58. std::string mapping_info;
  59. };
  60. #endif