2
0

miniupnpc.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* $Id: miniupnpc.h,v 1.18 2008/09/25 18:02:50 nanard Exp $ */
  2. /* Project: miniupnp
  3. * http://miniupnp.free.fr/
  4. * Author: Thomas Bernard
  5. * Copyright (c) 2005-2006 Thomas Bernard
  6. * This software is subjects to the conditions detailed
  7. * in the LICENCE file provided within this distribution */
  8. #ifndef __MINIUPNPC_H__
  9. #define __MINIUPNPC_H__
  10. #include "declspec.h"
  11. #include "igd_desc_parse.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /* Structures definitions : */
  16. struct UPNParg { const char * elt; const char * val; };
  17. int simpleUPnPcommand(int, const char *, const char *,
  18. const char *, struct UPNParg *,
  19. char *, int *);
  20. struct UPNPDev {
  21. struct UPNPDev * pNext;
  22. char * descURL;
  23. char * st;
  24. char buffer[2];
  25. };
  26. /* upnpDiscover()
  27. * discover UPnP devices on the network.
  28. * The discovered devices are returned as a chained list.
  29. * It is up to the caller to free the list with freeUPNPDevlist().
  30. * delay (in millisecond) is the maximum time for waiting any device
  31. * response.
  32. * If available, device list will be obtained from MiniSSDPd.
  33. * Default path for minissdpd socket will be used if minissdpdsock argument
  34. * is NULL.
  35. * If multicastif is not NULL, it will be used instead of the default
  36. * multicast interface for sending SSDP discover packets.
  37. * If sameport is not null, SSDP packets will be sent from the source port
  38. * 1900 (same as destination port) otherwise system assign a source port. */
  39. LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
  40. const char * minissdpdsock, int sameport);
  41. /* freeUPNPDevlist()
  42. * free list returned by upnpDiscover() */
  43. LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist);
  44. /* parserootdesc() :
  45. * parse root XML description of a UPnP device and fill the IGDdatas
  46. * structure. */
  47. LIBSPEC void parserootdesc(const char *, int, struct IGDdatas *);
  48. /* structure used to get fast access to urls
  49. * controlURL: controlURL of the WANIPConnection
  50. * ipcondescURL: url of the description of the WANIPConnection
  51. * controlURL_CIF: controlURL of the WANCommonInterfaceConfig
  52. */
  53. struct UPNPUrls {
  54. char * controlURL;
  55. char * ipcondescURL;
  56. char * controlURL_CIF;
  57. };
  58. /* UPNP_GetValidIGD() :
  59. * return values :
  60. * 0 = NO IGD found
  61. * 1 = A valid connected IGD has been found
  62. * 2 = A valid IGD has been found but it reported as
  63. * not connected
  64. * 3 = an UPnP device has been found but was not recognized as an IGD
  65. *
  66. * In any non zero return case, the urls and data structures
  67. * passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to
  68. * free allocated memory.
  69. */
  70. LIBSPEC int
  71. UPNP_GetValidIGD(struct UPNPDev * devlist,
  72. struct UPNPUrls * urls,
  73. struct IGDdatas * data,
  74. char * lanaddr, int lanaddrlen);
  75. /* UPNP_GetIGDFromUrl()
  76. * Used when skipping the discovery process.
  77. * return value :
  78. * 0 - Not ok
  79. * 1 - OK */
  80. LIBSPEC int
  81. UPNP_GetIGDFromUrl(const char * rootdescurl,
  82. struct UPNPUrls * urls,
  83. struct IGDdatas * data,
  84. char * lanaddr, int lanaddrlen);
  85. LIBSPEC void GetUPNPUrls(struct UPNPUrls *, struct IGDdatas *, const char *);
  86. LIBSPEC void FreeUPNPUrls(struct UPNPUrls *);
  87. /* Reads data from the specified socket.
  88. * Returns the number of bytes read if successful, zero if no bytes were
  89. * read or if we timed out. Returns negative if there was an error. */
  90. int ReceiveData(int socket, char * data, int length, int timeout);
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94. #endif