summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-01-14 19:21:07 +0100
committerMax Kellermann <max@musicpd.org>2019-01-14 19:21:07 +0100
commit1fa99da3c254a6a641bdf4eca35d781281c4c268 (patch)
treef13be1300ac20f59d4a45e0d680ac90b7ad3c0ea
parent22d669da181ba268d4fdcdd3bda33f64192f3701 (diff)
net/IPv[46]Address: make the initializers even more portable
Similar to 5a5229b49943c7032d83ae665552b4dc3e334820: use more C++14 constexpr.
-rw-r--r--src/net/IPv4Address.hxx9
-rw-r--r--src/net/IPv6Address.hxx34
2 files changed, 25 insertions, 18 deletions
diff --git a/src/net/IPv4Address.hxx b/src/net/IPv4Address.hxx
index d8be8e59d..f77dfe77e 100644
--- a/src/net/IPv4Address.hxx
+++ b/src/net/IPv4Address.hxx
@@ -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
diff --git a/src/net/IPv6Address.hxx b/src/net/IPv6Address.hxx
index 55ff9d6c9..23d030e84 100644
--- a/src/net/IPv6Address.hxx
+++ b/src/net/IPv6Address.hxx
@@ -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,