summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-08-20 15:47:53 +0200
committerMax Kellermann <max@musicpd.org>2018-08-20 15:48:52 +0200
commit82d0f68acfe7ae6767c6bd5fae653da49cb3b21a (patch)
treef5dfef8a0156e6cb372158ce7f6232fc765b01d9 /src/net
parent616c8383c0a4d59deca243437e5d8f07e03f763d (diff)
net/IPv4Address: add static method ConstructInAddrBE()
Diffstat (limited to 'src/net')
-rw-r--r--src/net/IPv4Address.hxx16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/net/IPv4Address.hxx b/src/net/IPv4Address.hxx
index d7344cede..f394382c8 100644
--- a/src/net/IPv4Address.hxx
+++ b/src/net/IPv4Address.hxx
@@ -54,6 +54,13 @@ class IPv4Address {
return {{{ a, b, c, d }}};
}
+ /**
+ * @param x the 32 bit IP address in network byte order
+ */
+ static constexpr struct in_addr ConstructInAddrBE(uint32_t x) noexcept {
+ return (struct in_addr){{.S_addr=x}};
+ }
+
static constexpr struct in_addr ConstructInAddr(uint32_t x) noexcept {
return ConstructInAddr(x >> 24, x >> 16, x >> 8, x);
}
@@ -68,8 +75,15 @@ class IPv4Address {
return ToBE32((a << 24) | (b << 16) | (c << 8) | d);
}
+ /**
+ * @param x the 32 bit IP address in network byte order
+ */
+ static constexpr struct in_addr ConstructInAddrBE(uint32_t x) noexcept {
+ return { x };
+ }
+
static constexpr struct in_addr ConstructInAddr(uint32_t x) noexcept {
- return { ToBE32(x) };
+ return ConstructInAddrBE(ToBE32(x));
}
static constexpr struct in_addr ConstructInAddr(uint8_t a, uint8_t b,