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