Boost.Asio will get you there, as in:
boost::asio::ip::address_v4::from_string("192.168.0.1").to_ulong();
IPv6 is a little more complicated, as you have to use boost::asio::ip::address_v6::from_string(addr).to_bytes()
which returns a boost::array<unsigned char, 16>
and convert from that yourself.