diff --git a/include/boost/asio/ip/basic_endpoint.hpp b/include/boost/asio/ip/basic_endpoint.hpp index 468b0868..aab90086 100644 --- a/include/boost/asio/ip/basic_endpoint.hpp +++ b/include/boost/asio/ip/basic_endpoint.hpp @@ -173,7 +173,7 @@ public: /// The protocol associated with the endpoint. protocol_type protocol() const { - if (is_v4()) + if (is_v4(data_)) return InternetProtocol::v4(); return InternetProtocol::v6(); } @@ -193,7 +193,7 @@ public: /// Get the underlying size of the endpoint in the native type. size_type size() const { - if (is_v4()) + if (is_v4(data_)) return sizeof(boost::asio::detail::sockaddr_in4_type); else return sizeof(boost::asio::detail::sockaddr_in6_type); @@ -219,7 +219,7 @@ public: /// the host's byte order. unsigned short port() const { - if (is_v4()) + if (is_v4(data_)) { return boost::asio::detail::socket_ops::network_to_host_short( reinterpret_cast( @@ -237,7 +237,7 @@ public: /// the host's byte order. void port(unsigned short port_num) { - if (is_v4()) + if (is_v4(data_)) { reinterpret_cast(data_).sin_port = boost::asio::detail::socket_ops::host_to_network_short(port_num); @@ -253,7 +253,7 @@ public: boost::asio::ip::address address() const { using namespace std; // For memcpy. - if (is_v4()) + if (is_v4(data_)) { const boost::asio::detail::sockaddr_in4_type& data = reinterpret_cast( @@ -307,15 +307,27 @@ public: private: // Helper function to determine whether the endpoint is IPv4. - bool is_v4() const - { #if defined(_AIX) - return data_.__ss_family == AF_INET; -#else - return data_.ss_family == AF_INET; -#endif + template struct is_v4_helper {}; + + template + static bool is_v4(const T& ss, is_v4_helper* = 0) + { + return ss.ss_family == AF_INET; } + template + static bool is_v4(const T& ss, is_v4_helper* = 0) + { + return ss.__ss_family == AF_INET; + } +#else + static bool is_v4(const boost::asio::detail::sockaddr_storage_type& ss) + { + return ss.ss_family == AF_INET; + } +#endif + // The underlying IP socket address. boost::asio::detail::sockaddr_storage_type data_; };