net/IPv[46]Address: make the initializers even more portable

Similar to 5a5229b49943c7032d83ae665552b4dc3e334820: use more C++14
constexpr.
This commit is contained in:
Max Kellermann 2019-01-14 19:21:07 +01:00
parent 22d669da18
commit 1fa99da3c2
2 changed files with 25 additions and 18 deletions

View File

@ -51,7 +51,12 @@ class IPv4Address {
#ifdef _WIN32
static constexpr struct in_addr ConstructInAddr(uint8_t a, uint8_t b,
uint8_t c, uint8_t d) noexcept {
return {{{ a, b, c, d }}};
struct in_addr result{};
result.s_net = a;
result.s_host = b;
result.s_lh = c;
result.s_impno = d;
return result;
}
#else
@ -66,7 +71,7 @@ class IPv4Address {
static constexpr struct in_addr ConstructInAddr(uint8_t a, uint8_t b,
uint8_t c, uint8_t d) noexcept {
return { ConstructInAddrT(a, b, c, d) };
return ConstructInAddrBE(ConstructInAddrT(a, b, c, d));
}
#endif

View File

@ -53,22 +53,24 @@ class IPv6Address {
uint16_t c, uint16_t d,
uint16_t e, uint16_t f,
uint16_t g, uint16_t h) noexcept {
return {{
#ifndef __HAIKU__
{
#endif
uint8_t(a >> 8), uint8_t(a),
uint8_t(b >> 8), uint8_t(b),
uint8_t(c >> 8), uint8_t(c),
uint8_t(d >> 8), uint8_t(d),
uint8_t(e >> 8), uint8_t(e),
uint8_t(f >> 8), uint8_t(f),
uint8_t(g >> 8), uint8_t(g),
uint8_t(h >> 8), uint8_t(h),
#ifndef __HAIKU__
}
#endif
}};
struct in6_addr result{};
result.s6_addr[0] = a >> 8;
result.s6_addr[1] = a;
result.s6_addr[2] = b >> 8;
result.s6_addr[3] = b;
result.s6_addr[4] = c >> 8;
result.s6_addr[5] = c;
result.s6_addr[6] = d >> 8;
result.s6_addr[7] = d;
result.s6_addr[8] = e >> 8;
result.s6_addr[9] = e;
result.s6_addr[10] = f >> 8;
result.s6_addr[11] = f;
result.s6_addr[12] = g >> 8;
result.s6_addr[13] = g;
result.s6_addr[14] = h >> 8;
result.s6_addr[15] = h;
return result;
}
static constexpr struct sockaddr_in6 Construct(struct in6_addr address,