Skip to content

Commit a949b9f

Browse files
authored
Merge pull request #2 from MarkusJx/master
Add support for multiple network adapters
2 parents 2162840 + 90347e0 commit a949b9f

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

include/upnp/igd.h

+6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ class igd final {
124124

125125
const std::string& friendly_name() const { return _upnp_device.friendly_name; }
126126

127+
/*
128+
* Discover IGD devices.
129+
*/
130+
static
131+
result<std::vector<igd>> discover(net::any_io_executor, const net::ip::address_v4& bind_ip, net::yield_context);
132+
127133
/*
128134
* Discover IGD devices.
129135
*/

include/upnp/ssdp.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <boost/range/begin.hpp> // needed by spawn
1010
#include <boost/range/end.hpp> // needed by spawn
1111
#include <boost/asio/spawn.hpp>
12+
#include <boost/asio/ip/address_v4.hpp>
1213

1314
namespace upnp { namespace ssdp {
1415

@@ -67,7 +68,7 @@ class query {
6768
query(query&&) = default;
6869
query& operator=(query&&) = default;
6970

70-
static result<query> start(net::any_io_executor, net::yield_context);
71+
static result<query> start(net::any_io_executor exec, const net::ip::address_v4& bind_ip, net::yield_context yield);
7172

7273
// May be called multiple times until error is of type error_code.
7374
// This let's callers of this function decide what to do when ssdp

src/igd.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,13 @@ igd::soap_request( string_view command
294294
}
295295

296296
/* static */
297-
result<std::vector<igd>> igd::discover(net::any_io_executor exec, net::yield_context yield)
297+
result<std::vector<igd>> igd::discover(net::any_io_executor exec
298+
, const net::ip::address_v4& bind_ip
299+
, net::yield_context yield)
298300
{
299301
using namespace std;
300302

301-
auto q = ssdp::query::start(exec, yield);
303+
auto q = ssdp::query::start(exec, bind_ip, yield);
302304
if (!q) return q.error();
303305
auto& query = q.value();
304306

@@ -373,6 +375,11 @@ result<std::vector<igd>> igd::discover(net::any_io_executor exec, net::yield_con
373375
return {std::move(igds)};
374376
}
375377

378+
result<std::vector<igd>> igd::discover(net::any_io_executor exec, net::yield_context yield)
379+
{
380+
return std::move(discover(exec, net::ip::address_v4::any(), yield));
381+
}
382+
376383
/* static */
377384
result<device>
378385
igd::query_root_device( net::any_io_executor exec

src/ssdp.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ struct query::state_t : std::enable_shared_from_this<state_t> {
4141
result<query::response, query::error::get_response>
4242
get_response(net::yield_context yield);
4343

44-
result<void> start(net::yield_context);
44+
result<void> start(const net::ip::address_v4 &bind_ip, net::yield_context);
4545

4646
void stop();
4747
};
4848

49-
result<void> query::state_t::start(net::yield_context yield)
49+
result<void> query::state_t::start(const net::ip::address_v4 &bind_ip, net::yield_context yield)
5050
{
5151
using udp = net::ip::udp;
5252
using namespace std::chrono;
@@ -55,7 +55,8 @@ result<void> query::state_t::start(net::yield_context yield)
5555
_socket.set_option(net::ip::multicast::join_group(_multicast_ep.address()));
5656

5757
error_code ec;
58-
_socket.bind(udp::endpoint(net::ip::address_v4::any(), 0), ec);
58+
_socket.bind(udp::endpoint(bind_ip, 0), ec);
59+
5960
if (ec) return ec;
6061

6162
std::stringstream ss;
@@ -231,10 +232,10 @@ query::query(std::shared_ptr<state_t> state)
231232
{}
232233

233234
/* static */
234-
result<query> query::start(net::any_io_executor exec, net::yield_context yield)
235+
result<query> query::start(net::any_io_executor exec, const net::ip::address_v4& bind_ip, net::yield_context yield)
235236
{
236237
auto st = std::make_shared<state_t>(exec);
237-
auto r = st->start(yield);
238+
auto r = st->start(bind_ip, yield);
238239
if (!r) return r.error();
239240
return query{std::move(st)};
240241
}

0 commit comments

Comments
 (0)