mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 13:47:56 +00:00
net/ipv4: convenience methods valid() and print()
Both methods are now available for Ipv4_address as well as for Ipv4_address_prefix. An IPv4 address is invalid if it contains zeros only. An IPv4 address prefix is invalid if its address is invalid and its prefix is 32. Ref #2139
This commit is contained in:
parent
9dddc905e2
commit
6276daecab
@ -22,10 +22,13 @@
|
||||
#include <util/endian.h>
|
||||
#include <net/netaddress.h>
|
||||
|
||||
namespace Genode { class Output; }
|
||||
|
||||
namespace Net
|
||||
{
|
||||
enum { IPV4_ADDR_LEN = 4 };
|
||||
typedef Network_address<IPV4_ADDR_LEN, '.', false> Ipv4_address;
|
||||
|
||||
class Ipv4_address;
|
||||
|
||||
class Ipv4_address_prefix;
|
||||
|
||||
@ -33,6 +36,16 @@ namespace Net
|
||||
}
|
||||
|
||||
|
||||
struct Net::Ipv4_address : Network_address<IPV4_ADDR_LEN, '.', false>
|
||||
{
|
||||
Ipv4_address(Genode::uint8_t value = 0) : Network_address(value) { }
|
||||
|
||||
Ipv4_address(void *src) : Network_address(src) { }
|
||||
|
||||
bool valid() const { return *this != Ipv4_address(); }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Data layout of this class conforms to an IPv4 packet (RFC 791)
|
||||
*
|
||||
@ -200,7 +213,11 @@ class Net::Ipv4_packet
|
||||
struct Net::Ipv4_address_prefix
|
||||
{
|
||||
Ipv4_address address;
|
||||
Genode::uint8_t prefix = 0;
|
||||
Genode::uint8_t prefix = 32;
|
||||
|
||||
bool valid() const { return address.valid(); }
|
||||
|
||||
void print(Genode::Output &output) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -80,3 +80,9 @@ Genode::uint16_t Ipv4_packet::calculate_checksum(Ipv4_packet const &packet)
|
||||
|
||||
const Ipv4_address Ipv4_packet::CURRENT((Genode::uint8_t)0x00);
|
||||
const Ipv4_address Ipv4_packet::BROADCAST((Genode::uint8_t)0xFF);
|
||||
|
||||
|
||||
void Ipv4_address_prefix::print(Genode::Output &output) const
|
||||
{
|
||||
Genode::print(output, address, "/", prefix);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user