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

Thanks to C++14, we can declare and fill variables inside `constexpr`
functions.  This means me can stop make assumptions on the `struct`
layouts without losing `constexpr`.

Closes #393
This commit is contained in:
Max Kellermann
2018-11-02 17:47:43 +01:00
parent bba22c9c8c
commit 5a5229b499
4 changed files with 21 additions and 48 deletions

View File

@@ -68,16 +68,12 @@ class IPv6Address {
static constexpr struct sockaddr_in6 Construct(struct in6_addr address,
uint16_t port,
uint32_t scope_id) noexcept {
return {
#if defined(__APPLE__)
sizeof(struct sockaddr_in6),
#endif
AF_INET6,
ToBE16(port),
0,
address,
scope_id,
};
struct sockaddr_in6 sin{};
sin.sin6_family = AF_INET6;
sin.sin6_port = ToBE16(port);
sin.sin6_addr = address;
sin.sin6_scope_id = scope_id;
return sin;
}
public: