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?