|
19 | 19 | using namespace std::literals; |
20 | 20 |
|
21 | 21 | namespace upnp { |
22 | | - constexpr auto INET6_ADDRESS_STRLEN = 46; |
23 | | - |
24 | | - constexpr auto PORT_MAPPING_LIFETIME = 3600s; |
25 | | - constexpr auto REFRESH_INTERVAL = 120s; |
26 | | - |
27 | | - constexpr auto IPv4 = 0; |
28 | | - constexpr auto IPv6 = 1; |
29 | | - |
30 | | - using device_t = util::safe_ptr<UPNPDev, freeUPNPDevlist>; |
31 | | - |
32 | | - KITTY_USING_MOVE_T(urls_t, UPNPUrls, , { |
33 | | - FreeUPNPUrls(&el); |
34 | | - }); |
35 | 22 |
|
36 | 23 | struct mapping_t { |
37 | 24 | struct { |
@@ -59,6 +46,19 @@ namespace upnp { |
59 | 46 | return "Unknown status"sv; |
60 | 47 | } |
61 | 48 |
|
| 49 | + /** |
| 50 | + * This function is a wrapper around UPNP_GetValidIGD() that returns the status code. There is a pre-processor |
| 51 | + * check to determine which version of the function to call based on the version of the MiniUPnPc library. |
| 52 | + */ |
| 53 | + int |
| 54 | + UPNP_GetValidIGDStatus(device_t &device, urls_t *urls, IGDdatas *data, std::array<char, INET6_ADDRESS_STRLEN> &lan_addr) { |
| 55 | +#if (MINIUPNPC_API_VERSION >= 18) |
| 56 | + return UPNP_GetValidIGD(device.get(), &urls->el, data, lan_addr.data(), lan_addr.size(), nullptr, 0); |
| 57 | +#else |
| 58 | + return UPNP_GetValidIGD(device.get(), &urls->el, data, lan_addr.data(), lan_addr.size()); |
| 59 | +#endif |
| 60 | + } |
| 61 | + |
62 | 62 | class deinit_t: public platf::deinit_t { |
63 | 63 | public: |
64 | 64 | deinit_t() { |
@@ -109,7 +109,7 @@ namespace upnp { |
109 | 109 | IGDdatas data; |
110 | 110 | urls_t urls; |
111 | 111 | std::array<char, INET6_ADDRESS_STRLEN> lan_addr; |
112 | | - auto status = UPNP_GetValidIGD(device.get(), &urls.el, &data, lan_addr.data(), lan_addr.size()); |
| 112 | + auto status = upnp::UPNP_GetValidIGDStatus(device, &urls, &data, lan_addr); |
113 | 113 | if (status != 1 && status != 2) { |
114 | 114 | BOOST_LOG(debug) << "No valid IPv6 IGD: "sv << status_string(status); |
115 | 115 | return false; |
@@ -331,7 +331,7 @@ namespace upnp { |
331 | 331 | std::array<char, INET6_ADDRESS_STRLEN> lan_addr; |
332 | 332 |
|
333 | 333 | urls_t urls; |
334 | | - auto status = UPNP_GetValidIGD(device.get(), &urls.el, &data, lan_addr.data(), lan_addr.size()); |
| 334 | + auto status = upnp::UPNP_GetValidIGDStatus(device, &urls, &data, lan_addr); |
335 | 335 | if (status != 1 && status != 2) { |
336 | 336 | BOOST_LOG(error) << status_string(status); |
337 | 337 | mapped = false; |
|
0 commit comments