Commit 82d0f68a authored by Max Kellermann's avatar Max Kellermann

net/IPv4Address: add static method ConstructInAddrBE()

parent 616c8383
...@@ -54,6 +54,13 @@ class IPv4Address { ...@@ -54,6 +54,13 @@ class IPv4Address {
return {{{ a, b, c, d }}}; 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 { static constexpr struct in_addr ConstructInAddr(uint32_t x) noexcept {
return ConstructInAddr(x >> 24, x >> 16, x >> 8, x); return ConstructInAddr(x >> 24, x >> 16, x >> 8, x);
} }
...@@ -68,8 +75,15 @@ class IPv4Address { ...@@ -68,8 +75,15 @@ class IPv4Address {
return ToBE32((a << 24) | (b << 16) | (c << 8) | d); 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 { 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, static constexpr struct in_addr ConstructInAddr(uint8_t a, uint8_t b,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment