miniupnpc.h 5.0 KB

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