1 #ifndef LIBFILEZILLA_IPUTILS_HEADER 2 #define LIBFILEZILLA_IPUTILS_HEADER 3 4 #include "libfilezilla.hpp" 5 6 /** \file 7 * \brief Various functions to deal with IP address strings 8 */ 9 10 namespace fz { 11 12 /** \brief Given a shortened IPv6 address, returns the full, unshortened address 13 * 14 * If passed address is encloded in square brackets, they are stripped. 15 * 16 * Returns an empty string if the passed string isn't a valid IPv6 address. 17 */ 18 std::string FZ_PUBLIC_SYMBOL get_ipv6_long_form(std::string_view const& short_address); 19 std::wstring FZ_PUBLIC_SYMBOL get_ipv6_long_form(std::wstring_view const& short_address); 20 21 /** \brief Tests whether the passed IP address is routable on the public Internet. 22 * 23 * Unroutable addresss are: 24 * \li Invalid addresses 25 * \li ::/128 (the unspecified address) 26 * \li ::1/128 (localhost) 27 * \li fe80::/10 (link-local) 28 * \li fc00::/7 (unique local) 29 * \li 127.0.0.0/8 (localhost) 30 * \li 10.0.0.0/8 (private) 31 * \li 172.16.0.0/12 (private) 32 * \li 192.168.0.0/16 (private) 33 * \li 169.254.0.0/16 (link-local) 34 * 35 * All other addresses are assumed routable. 36 */ 37 bool FZ_PUBLIC_SYMBOL is_routable_address(std::string_view const& address); 38 bool FZ_PUBLIC_SYMBOL is_routable_address(std::wstring_view const& address); 39 40 enum class address_type 41 { 42 unknown, 43 ipv4, 44 ipv6 45 }; 46 47 /** \brief Gets the type of the passed IP address. */ 48 address_type FZ_PUBLIC_SYMBOL get_address_type(std::string_view const& address); 49 address_type FZ_PUBLIC_SYMBOL get_address_type(std::wstring_view const& address); 50 51 } 52 53 #endif 54