Problem with homegrown. porting to ipv6
Hi, I am doing a homegrown project, which i am adding support to ipv6 where i 2 different codes: *First code:* my_Acceptor = new tcp::acceptor(myService, tcp::endpoint(boost::asio::ip::address_v4::loopback(),port)); *Second code:* my_acceptor = new tcp::acceptor(myContext, tcp::endpoint(ifallowed ? boost::asio::ip::address_v4::any() : boost::asio::ip::address_v4::loopback(),port)); What I wanted to ask is, is there any way in boost by which we can first try things on ipv6 and if that doesn't work fall to ipv4. *Since it is just loopback address, is it a better way than this, for the first code* try{ my_Acceptor = new tcp::acceptor(myService, tcp::endpoint(boost::asio::ip::address_v6::loopback(),port)); } catch(boost::system::system_error& e) { printf("Error Starting on v6, trying on v4: %s\n", e.what()); } try{ my_Acceptor = new tcp::acceptor(myService, tcp::endpoint(boost::asio::ip::address_v4::loopback(),port)); } catch(boost::system::system_error& e) { printf("Error Starting on v4,: %s\n", e.what()); return; }
participants (1)
-
Tarun Batra