26 constexpr
Addr(u16 msb, u16 lsb)
27 :
value(65536ul * msb + lsb) {}
29 constexpr
Addr(u8 a, u8 b, u8 c, u8 d)
30 :
value(16777216ul * a + 65536ul * b + 256ul * c + d) {}
32 Addr& operator=(
const Addr& t) =
default;
41 {wr->write_u32(
value);}
43 {
value = rd->read_u32();
return true;}
60 constexpr u32 cidr_prefix(
unsigned npre) {
61 return (npre ? ~((0x80000000 >> (npre-1)) - 1) : 0);
71 constexpr
Mask(
unsigned npre)
72 :
Addr(satcat5::ip::cidr_prefix(npre)) {}
74 constexpr
Mask(u8 a, u8 b, u8 c, u8 d)
79 Mask& operator=(
const Mask& t) =
default;
126 Port& operator=(
const Port& t) =
default;
135 {wr->write_u16(
value);}
137 {
value = rd->read_u16();
return true;}
145 HDR_MIN_SHORTS = 2 * HDR_MIN_WORDS,
146 HDR_MIN_BYTES = 4 * HDR_MIN_WORDS,
148 HDR_MAX_SHORTS = 2 * HDR_MAX_WORDS,
149 HDR_MAX_BYTES = 4 * HDR_MAX_WORDS;
162 ADDR_NONE(0, 0, 0, 0),
163 ADDR_BROADCAST(255, 255, 255, 255),
164 ADDR_LOOPBACK(127, 0, 0, 1),
165 ADDR_ALL_SYSTEMS(224, 0, 0, 1),
166 ADDR_ALL_ROUTERS(224, 0, 0, 2),
167 ADDR_PTP_PDELAY(224, 0, 0, 107),
168 ADDR_PTP_PRIMARY(224, 0, 1, 129);
170 DEFAULT_ROUTE = {ADDR_NONE, MASK_NONE},
171 UDP_MULTICAST = {Addr(224, 0, 0, 0), Mask(4)};
173 constexpr u8 PROTO_ICMP = 0x01;
174 constexpr u8 PROTO_IGMP = 0x02;
175 constexpr u8 PROTO_TCP = 0x06;
176 constexpr u8 PROTO_UDP = 0x11;
190 constexpr
unsigned ver() const
191 {
return (
data[0] >> 12) & 0x0F;}
192 constexpr
unsigned ihl() const
193 {
return (
data[0] >> 8) & 0x0F;}
196 constexpr u16
id() const
199 {
return data[3] & 0xBFFF;}
203 {
return (u8)(
data[4] >> 8);}
205 {
return (u8)(
data[4] & 0x00FF);}
220 void chk_incr32(u32 prev, u32 next);
248 u16 checksum(
unsigned wcount,
const u16* data, u16 prev = UINT16_MAX);
Abstract API for reading byte-streams and packets.
Abstract API for writing byte-streams and packets.
Internal buffer used by the Log class.
I/O interface core definitions.
IPv4 address is a 32-bit unsigned integer.
constexpr satcat5::ip::Addr operator+(unsigned offset) const
Commonly used operators.
u32 value
Raw access to the underlying representation.
constexpr bool operator==(const satcat5::ip::Addr &other) const
Commonly used operators.
bool is_multicast() const
IP multicast (224.*.*.*)
bool read_from(satcat5::io::Readable *rd)
Commonly used operators.
constexpr Addr(u8 a, u8 b, u8 c, u8 d)
Constructor in human-readable form (a.b.c.d)
bool is_unicast() const
Any normal single-destination address.
void log_to(satcat5::log::LogBuffer &wr) const
Format this IP address in standard form, e.g., "192.168.1.2".
constexpr bool operator!=(const satcat5::ip::Addr &other) const
Commonly used operators.
constexpr Addr()
Constructor for the null address (0.0.0.0).
bool is_valid() const
Any nonzero address.
bool is_reserved() const
Reserved blocks (0.*.*.* or 127.*.*.*)
constexpr Addr(u16 msb, u16 lsb)
Constructor for two 16-bit integers.
bool is_broadcast() const
Limited broadcast (255.255.255.255)
void write_to(satcat5::io::Writeable *wr) const
Commonly used operators.
constexpr Addr(u32 ip)
Constructor for a single 32-bit integer.
IPv4 subnet masks share functionality with a basic address, but are constructed differently to match ...
constexpr Mask()
Constructor for the wildcard mask (match all addresses).
unsigned prefix() const
Convert this subnet-mask to a CIDR prefix length.
constexpr Mask(u8 a, u8 b, u8 c, u8 d)
Constructor in subnet-mask form (a.b.c.d).
constexpr Mask(unsigned npre)
Constructor for the a CIDR prefix (e.g., /24).
constexpr Mask(const satcat5::ip::Addr &addr)
Copy-constructor.
UDP and TCP ports are both 16-bit unsigned integers.
constexpr bool operator!=(const satcat5::ip::Port &other) const
Commonly used operators.
bool read_from(satcat5::io::Readable *rd)
Commonly used operators.
void write_to(satcat5::io::Writeable *wr) const
Commonly used operators.
u16 value
Raw access to the underlying representation.
constexpr Port(u16 port)
Constructor.
constexpr bool operator==(const satcat5::ip::Port &other) const
Commonly used operators.
An IPv4 subnet consists of a base address and a subnet mask.
void log_to(satcat5::log::LogBuffer &wr) const
Format this subnet in CIDR form, e.g., "192.168.1.0/24".
unsigned prefix() const
Get the CIDR prefix length for this subnet.
satcat5::ip::Mask mask
Subnet mask.
constexpr bool operator!=(const satcat5::ip::Subnet &other) const
Commonly used operators.
constexpr bool operator==(const satcat5::ip::Addr &other) const
Commonly used operators.
constexpr bool contains(const satcat5::ip::Addr &other) const
Does this subnet contain the given address?
satcat5::ip::Addr addr
Base address.
constexpr bool operator==(const satcat5::ip::Subnet &other) const
Commonly used operators.