c++ - How to use miniupnpc with Boost.Asio UDP when binding a socket to a random port -
i'm astonished lack of documentation on miniupnp, believe there's lot of people using it, no documentation @ all, found piece of code in source of raknet guide me.
now i'm having conceptual issue...
i'm developing app connects server via udp (the server should accessible, server udp port specific 1 open, , can test using open port checker), server puts 2 or more clients talking each other (p2p), need circumvent nat in clients work.
i have nat punch through working, , solves lots of cases.
now, want add upnp functionality, attack nat issue too.
i'm using miniupnpc, , handle connections boost.asio.
struct upnpdev * devlist = 0; devlist = upnpdiscover(2000, 0, 0, 0, 0, 0); if (devlist) { std::cout << "\nlist of upnp devices found on network :\n"; struct upnpdev * device; for(device = devlist; device; device = device->pnext) { std::cout << "\ndesc: " << device->descurl << "\n st: " << device->st << "\n"; } char lanaddr[64]; /* ip address on lan */ struct upnpurls urls; struct igddatas data; if (upnp_getvalidigd(devlist, &urls, &data, lanaddr, sizeof(lanaddr)) == 1) { string port = lexical_cast<string>(socket->local_endpoint().port()); int r = upnp_addportmapping(urls.controlurl, data.first.servicetype, port.c_str(), port.c_str(), lanaddr, 0, "udp", 0, "0"); if (r != upnpcommand_success) { std::cout << "\nupnp fail"; } char intport[6]; char intclient[16]; char desc[128]; char enabled[128]; char leaseduration[128]; r = upnp_getspecificportmappingentry(urls.controlurl, data.first.servicetype, port.c_str(), "udp", 0, intclient, intport, desc, enabled, leaseduration); if (r != upnpcommand_success) { std::cout << "\nupnp fail"; }else { std::cout << "\nupnp success on port " << port; } } }
as can see, execute upnp after having bound socket (i bind without specific port, this:)
asio::udp::socket socket(*this->ioservice, asio::udp::endpoint());
my question is, upnp execution makes sense? socket use upnp port map if execute upnp on random port bound socket after bind it?
thanks guys!
Comments
Post a Comment