6 #include <satcat5/udp_core.h>
7 #include <satcat5/udp_dispatch.h>
9 using satcat5::ip::PROTO_UDP;
11 using satcat5::udp::HEADER_BYTES;
12 using satcat5::udp::PORT_NONE;
16 , m_addr(nullptr, PROTO_UDP)
17 , m_dstport(PORT_NONE)
18 , m_srcport(PORT_NONE)
24 if (
iface && !m_iface) {
38 m_srcport = (m_iface && srcport == PORT_NONE)
40 m_addr.
connect(dstaddr, dstmac, vtag);
50 m_srcport = (m_iface && srcport == PORT_NONE)
58 && m_iface->reply_src() == dstport()
59 && m_iface->reply_dst() == srcport();
68 return m_iface->iface()->
next_header(PROTO_UDP, dstaddr(), len + HEADER_BYTES);
72 return m_iface ? m_iface->
open_write(m_addr, m_srcport, m_dstport, len) :
nullptr;
78 m_dstport = m_iface->reply_src();
79 m_srcport = m_iface->reply_dst();
86 wr->write_u16(length);
95 length = rd->read_u16();
Abstract API for reading byte-streams and packets.
virtual unsigned get_read_ready() const =0
How many bytes can be read without blocking?
Abstract API for writing byte-streams and packets.
void connect(const satcat5::ip::Addr &dstaddr, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Automatic address resolution using routing table + ARP.
void save_reply_address() override
Bind this Address object to the parent interface's current reply address, as provided in net::Dispatc...
bool matches_reply_address() const override
Does this Address object match the parent interface's current reply address? Multicast destinations s...
void init(satcat5::ip::Dispatch *iface)
Deferred initialization of the upstream interface.
satcat5::ip::Header next_header(u8 protocol, const satcat5::ip::Addr &dst, unsigned inner_bytes, u8 ttl=SATCAT5_IP_TTL)
Create a basic IPv4 header with the specified information.
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
Implementation of "net::Address" for UDP Dispatch.
void save_reply_address() override
Bind this Address object to the parent interface's current reply address, as provided in net::Dispatc...
satcat5::net::Dispatch * iface() const override
Fetch a pointer to the underlying interface.
satcat5::io::Writeable * open_write(unsigned len) override
Open a new frame to the designated address and type.
void connect(const satcat5::udp::Addr &dstaddr, const satcat5::eth::MacAddr &dstmac, const satcat5::udp::Port &dstport, const satcat5::udp::Port &srcport=satcat5::udp::PORT_NONE, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Manual address resolution (user supplies IP + MAC).
bool matches_reply_address() const override
Does this Address object match the parent interface's current reply address? Multicast destinations s...
void init(satcat5::udp::Dispatch *iface)
Deferred initialization of the upstream interface.
Dispatcher sorts incoming UDP messages by port index.
satcat5::io::Writeable * open_write(satcat5::ip::Address &addr, const satcat5::udp::Port &src, const satcat5::udp::Port &dst, unsigned len)
Send a datagram to the designated UDP address and port.
satcat5::udp::Port next_free_port()
Get the next unclaimed dynamically-allocated port index.
An Ethernet MAC address (with serializable interface).
Header contents for an 802.1Q Virtual-LAN tag.
IPv4 address is a 32-bit unsigned integer.
UDP and TCP ports are both 16-bit unsigned integers.