miniupnpc.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* $Id: miniupnpc.h,v 1.53 2018/05/07 11:05:16 nanard Exp $ */
  2. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  3. * Project: miniupnp
  4. * http://miniupnp.free.fr/
  5. * Author: Thomas Bernard
  6. * Copyright (c) 2005-2018 Thomas Bernard
  7. * This software is subjects to the conditions detailed
  8. * in the LICENCE file provided within this distribution */
  9. #ifndef MINIUPNPC_H_INCLUDED
  10. #define MINIUPNPC_H_INCLUDED
  11. #include "miniupnpc_declspec.h"
  12. #include "igd_desc_parse.h"
  13. #include "upnpdev.h"
  14. /* error codes : */
  15. #define UPNPDISCOVER_SUCCESS (0)
  16. #define UPNPDISCOVER_UNKNOWN_ERROR (-1)
  17. #define UPNPDISCOVER_SOCKET_ERROR (-101)
  18. #define UPNPDISCOVER_MEMORY_ERROR (-102)
  19. /* versions : */
  20. #define MINIUPNPC_VERSION "2.1"
  21. #define MINIUPNPC_API_VERSION 17
  22. /* Source port:
  23. Using "1" as an alias for 1900 for backwards compatibility
  24. (presuming one would have used that for the "sameport" parameter) */
  25. #define UPNP_LOCAL_PORT_ANY 0
  26. #define UPNP_LOCAL_PORT_SAME 1
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Structures definitions : */
  31. struct UPNParg { const char * elt; const char * val; };
  32. char *
  33. simpleUPnPcommand(int, const char *, const char *,
  34. const char *, struct UPNParg *,
  35. int *);
  36. /* upnpDiscover()
  37. * discover UPnP devices on the network.
  38. * The discovered devices are returned as a chained list.
  39. * It is up to the caller to free the list with freeUPNPDevlist().
  40. * delay (in millisecond) is the maximum time for waiting any device
  41. * response.
  42. * If available, device list will be obtained from MiniSSDPd.
  43. * Default path for minissdpd socket will be used if minissdpdsock argument
  44. * is NULL.
  45. * If multicastif is not NULL, it will be used instead of the default
  46. * multicast interface for sending SSDP discover packets.
  47. * If localport is set to UPNP_LOCAL_PORT_SAME(1) SSDP packets will be sent
  48. * from the source port 1900 (same as destination port), if set to
  49. * UPNP_LOCAL_PORT_ANY(0) system assign a source port, any other value will
  50. * be attempted as the source port.
  51. * "searchalltypes" parameter is useful when searching several types,
  52. * if 0, the discovery will stop with the first type returning results.
  53. * TTL should default to 2. */
  54. MINIUPNP_LIBSPEC struct UPNPDev *
  55. upnpDiscover(int delay, const char * multicastif,
  56. const char * minissdpdsock, int localport,
  57. int ipv6, unsigned char ttl,
  58. int * error);
  59. MINIUPNP_LIBSPEC struct UPNPDev *
  60. upnpDiscoverAll(int delay, const char * multicastif,
  61. const char * minissdpdsock, int localport,
  62. int ipv6, unsigned char ttl,
  63. int * error);
  64. MINIUPNP_LIBSPEC struct UPNPDev *
  65. upnpDiscoverDevice(const char * device, int delay, const char * multicastif,
  66. const char * minissdpdsock, int localport,
  67. int ipv6, unsigned char ttl,
  68. int * error);
  69. MINIUPNP_LIBSPEC struct UPNPDev *
  70. upnpDiscoverDevices(const char * const deviceTypes[],
  71. int delay, const char * multicastif,
  72. const char * minissdpdsock, int localport,
  73. int ipv6, unsigned char ttl,
  74. int * error,
  75. int searchalltypes);
  76. /* parserootdesc() :
  77. * parse root XML description of a UPnP device and fill the IGDdatas
  78. * structure. */
  79. MINIUPNP_LIBSPEC void parserootdesc(const char *, int, struct IGDdatas *);
  80. /* structure used to get fast access to urls
  81. * controlURL: controlURL of the WANIPConnection
  82. * ipcondescURL: url of the description of the WANIPConnection
  83. * controlURL_CIF: controlURL of the WANCommonInterfaceConfig
  84. * controlURL_6FC: controlURL of the WANIPv6FirewallControl
  85. */
  86. struct UPNPUrls {
  87. char * controlURL;
  88. char * ipcondescURL;
  89. char * controlURL_CIF;
  90. char * controlURL_6FC;
  91. char * rootdescURL;
  92. };
  93. /* UPNP_GetValidIGD() :
  94. * return values :
  95. * 0 = NO IGD found
  96. * 1 = A valid connected IGD has been found
  97. * 2 = A valid IGD has been found but it reported as
  98. * not connected
  99. * 3 = an UPnP device has been found but was not recognized as an IGD
  100. *
  101. * In any non zero return case, the urls and data structures
  102. * passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to
  103. * free allocated memory.
  104. */
  105. MINIUPNP_LIBSPEC int
  106. UPNP_GetValidIGD(struct UPNPDev * devlist,
  107. struct UPNPUrls * urls,
  108. struct IGDdatas * data,
  109. char * lanaddr, int lanaddrlen);
  110. /* UPNP_GetIGDFromUrl()
  111. * Used when skipping the discovery process.
  112. * When succeding, urls, data, and lanaddr arguments are set.
  113. * return value :
  114. * 0 - Not ok
  115. * 1 - OK */
  116. MINIUPNP_LIBSPEC int
  117. UPNP_GetIGDFromUrl(const char * rootdescurl,
  118. struct UPNPUrls * urls,
  119. struct IGDdatas * data,
  120. char * lanaddr, int lanaddrlen);
  121. MINIUPNP_LIBSPEC void
  122. GetUPNPUrls(struct UPNPUrls *, struct IGDdatas *,
  123. const char *, unsigned int);
  124. MINIUPNP_LIBSPEC void
  125. FreeUPNPUrls(struct UPNPUrls *);
  126. /* return 0 or 1 */
  127. MINIUPNP_LIBSPEC int UPNPIGD_IsConnected(struct UPNPUrls *, struct IGDdatas *);
  128. #ifdef __cplusplus
  129. }
  130. #endif
  131. #endif