diff --git a/repos/os/include/net/ipv4.h b/repos/os/include/net/ipv4.h index 2997cd746a..140c91a514 100644 --- a/repos/os/include/net/ipv4.h +++ b/repos/os/include/net/ipv4.h @@ -43,6 +43,14 @@ struct Net::Ipv4_address : Network_address Ipv4_address(void *src) : Network_address(src) { } bool valid() const { return *this != Ipv4_address(); } + + Genode::uint32_t to_uint32_big_endian() const; + + static Ipv4_address from_uint32_big_endian(Genode::uint32_t ip_raw); + + Genode::uint32_t to_uint32_little_endian() const; + + static Ipv4_address from_uint32_little_endian(Genode::uint32_t ip_raw); } __attribute__((packed)); diff --git a/repos/os/src/lib/net/ipv4.cc b/repos/os/src/lib/net/ipv4.cc index 5be75d3b40..daf6f8c46d 100644 --- a/repos/os/src/lib/net/ipv4.cc +++ b/repos/os/src/lib/net/ipv4.cc @@ -38,6 +38,46 @@ void Net::Ipv4_packet::print(Genode::Output &output) const } +uint32_t Ipv4_address::to_uint32_big_endian() const +{ + return addr[0] | + addr[1] << 8 | + addr[2] << 16 | + addr[3] << 24; +} + + +Ipv4_address Ipv4_address::from_uint32_big_endian(uint32_t ip_raw) +{ + Ipv4_address ip; + ip.addr[0] = ip_raw; + ip.addr[1] = ip_raw >> 8; + ip.addr[2] = ip_raw >> 16; + ip.addr[3] = ip_raw >> 24; + return ip; +} + + +uint32_t Ipv4_address::to_uint32_little_endian() const +{ + return addr[3] | + addr[2] << 8 | + addr[1] << 16 | + addr[0] << 24; +} + + +Ipv4_address Ipv4_address::from_uint32_little_endian(uint32_t ip_raw) +{ + Ipv4_address ip; + ip.addr[3] = ip_raw; + ip.addr[2] = ip_raw >> 8; + ip.addr[1] = ip_raw >> 16; + ip.addr[0] = ip_raw >> 24; + return ip; +} + + struct Scanner_policy_number { static bool identifier_char(char c, unsigned i ) {