2

Upon starting my program I need to retrieve the local (LAN) address of the machine running it. The way I do this is the following:

try {
    asio::io_service ioService;
    asio::udp::resolver resolver(ioService);
    asio::udp::query lanQuery(asio::udp::v4(), asio::ip::host_name(), "");
    boost::system::error_code error;
    auto endpointIter = resolver.resolve(lanQuery, error);
    if (error || endpointIter == endpoint_iterator()) {
        //TREATS ERROR
        return;
    }
    //BUILD ENDPOINT
    asio::udp::endpoint endpoint(*endpointIter); //CRASHES HERE FOR SOME PPL
catch (...) {//TREATS ERROR}

This work for 90% of the users, but for a few people it crashes in the last line. Idk what to do, since I test the returned iterator, the error code, and also I enclosed the whole code with a try...catch (...) block.

I can't even treat the exception, the program simply crashes and that's it. I'm using Boost 1.64 but this issue happens since forever.

I haven't noticed any pattern for this crash, it seems to crash for random people with all kinds of hardware/software/OS.

Am I doing something wrong? Does anyone see a reason why this code would crash?

Aymar Fisherman
  • 388
  • 1
  • 8

1 Answers1

0

Is is correct to compare endpointIter with default constructed endpoint? In my source, i compare against default constructed iterator:

auto endpointIter = resolver.resolve(lanQuery, error);
decltype(endpointIter) end;

for(;endpointIter != end; ++endpointIter)
{
  asio::udp::endpoint endpoint(*endpointIter);
  ...
}
Dobby
  • 46
  • 1
  • 5