net/IPv[46]Address: make the initializers even more portable
Similar to 5a5229b49943c7032d83ae665552b4dc3e334820: use more C++14 constexpr.
This commit is contained in:
parent
22d669da18
commit
1fa99da3c2
|
@ -51,7 +51,12 @@ class IPv4Address {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static constexpr struct in_addr ConstructInAddr(uint8_t a, uint8_t b,
|
static constexpr struct in_addr ConstructInAddr(uint8_t a, uint8_t b,
|
||||||
uint8_t c, uint8_t d) noexcept {
|
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
|
#else
|
||||||
|
|
||||||
|
@ -66,7 +71,7 @@ class IPv4Address {
|
||||||
|
|
||||||
static constexpr struct in_addr ConstructInAddr(uint8_t a, uint8_t b,
|
static constexpr struct in_addr ConstructInAddr(uint8_t a, uint8_t b,
|
||||||
uint8_t c, uint8_t d) noexcept {
|
uint8_t c, uint8_t d) noexcept {
|
||||||
return { ConstructInAddrT(a, b, c, d) };
|
return ConstructInAddrBE(ConstructInAddrT(a, b, c, d));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -53,22 +53,24 @@ class IPv6Address {
|
||||||
uint16_t c, uint16_t d,
|
uint16_t c, uint16_t d,
|
||||||
uint16_t e, uint16_t f,
|
uint16_t e, uint16_t f,
|
||||||
uint16_t g, uint16_t h) noexcept {
|
uint16_t g, uint16_t h) noexcept {
|
||||||
return {{
|
struct in6_addr result{};
|
||||||
#ifndef __HAIKU__
|
result.s6_addr[0] = a >> 8;
|
||||||
{
|
result.s6_addr[1] = a;
|
||||||
#endif
|
result.s6_addr[2] = b >> 8;
|
||||||
uint8_t(a >> 8), uint8_t(a),
|
result.s6_addr[3] = b;
|
||||||
uint8_t(b >> 8), uint8_t(b),
|
result.s6_addr[4] = c >> 8;
|
||||||
uint8_t(c >> 8), uint8_t(c),
|
result.s6_addr[5] = c;
|
||||||
uint8_t(d >> 8), uint8_t(d),
|
result.s6_addr[6] = d >> 8;
|
||||||
uint8_t(e >> 8), uint8_t(e),
|
result.s6_addr[7] = d;
|
||||||
uint8_t(f >> 8), uint8_t(f),
|
result.s6_addr[8] = e >> 8;
|
||||||
uint8_t(g >> 8), uint8_t(g),
|
result.s6_addr[9] = e;
|
||||||
uint8_t(h >> 8), uint8_t(h),
|
result.s6_addr[10] = f >> 8;
|
||||||
#ifndef __HAIKU__
|
result.s6_addr[11] = f;
|
||||||
}
|
result.s6_addr[12] = g >> 8;
|
||||||
#endif
|
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,
|
static constexpr struct sockaddr_in6 Construct(struct in6_addr address,
|
||||||
|
|
Loading…
Reference in New Issue