@@ -57,8 +57,9 @@ class ipv6_address {
5757 [[nodiscard]] constexpr auto to_bytes () const noexcept -> std::array<unsigned char, 16> {
5858 std::array<unsigned char , 16 > bytes{};
5959 for (auto i = 0UL ; i < address_.size (); ++i) {
60- bytes[i * 2 ] = static_cast <unsigned char >(address_[i] >> 8u ); // NOLINT
61- bytes[i * 2 + 1 ] = static_cast <unsigned char >(address_[i]); // NOLINT
60+ auto piece = from_network_byte_order (address_[i]);
61+ bytes[i * 2 ] = static_cast <unsigned char >(piece >> 8u ); // NOLINT
62+ bytes[i * 2 + 1 ] = static_cast <unsigned char >(piece); // NOLINT
6263 }
6364 return bytes;
6465 }
@@ -68,13 +69,19 @@ class ipv6_address {
6869 using namespace std ::string_literals;
6970 using namespace std ::string_view_literals;
7071
72+ // Convert address to host byte order for processing
73+ auto address = std::array<unsigned short , 8 >{};
74+ for (auto i = 0UL ; i < address_.size (); ++i) {
75+ address[i] = from_network_byte_order (address_[i]); // NOLINT
76+ }
77+
7178 auto output = " " s;
7279 auto compress = std::optional<std::size_t >();
7380
7481 auto sequences = static_vector<std::pair<std::size_t , std::size_t >, 8 >{};
7582 auto in_sequence = false ;
7683
77- auto first = std::cbegin (address_ ), last = std::cend (address_ );
84+ auto first = std::cbegin (address ), last = std::cend (address );
7885 auto it = first;
7986 while (true ) {
8087 if (*it == 0 ) {
@@ -114,7 +121,7 @@ class ipv6_address {
114121
115122 auto ignore0 = false ;
116123 for (auto i = 0UL ; i <= 7UL ; ++i) {
117- if (ignore0 && (address_ [i] == 0 )) { // NOLINT
124+ if (ignore0 && (address [i] == 0 )) { // NOLINT
118125 continue ;
119126 } else if (ignore0) {
120127 ignore0 = false ;
@@ -129,7 +136,7 @@ class ipv6_address {
129136
130137 constexpr auto separator = [](auto i) { return (i != 7 ) ? " :" sv : " " sv; };
131138
132- output += std::format (" {:x}{}" , address_ [i], separator (i)); // NOLINT
139+ output += std::format (" {:x}{}" , address [i], separator (i)); // NOLINT
133140 }
134141
135142 return output;
0 commit comments