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.

64 lines
1.5 KiB

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