30#ifndef PROTOCORE_UDP_COMMON_H
31#define PROTOCORE_UDP_COMMON_H
33#include "endian/endian.h"
34#include "memoria_anularis/memoria_anularis.h"
35#include "octetus_introitus_exitus/octetus_introitus_exitus.h"
41#define PROTOCORE_UDP_DGRAM_HDR 21u
54 EMBED_CALL(byteio.put, OctetusCfg, .write_span = w, .byte = (uint8_t)d->
addr.
family);
55 EMBED_CALL(byteio.put_be, OctetusCfg, .write_span = w, .value = d->
port, .bytes = 2);
56 EMBED_CALL(byteio.put_be, OctetusCfg, .write_span = w, .value = d->
len, .bytes = 2);
57 EMBED_CALL(byteio.put_be, OctetusCfg, .write_span = w,
58 .value = EMBED_CALL(magna_extremitas.rd, EndianCfg, .src = d->
addr.
bytes, .width = MMGR_ENDIAN_64),
60 EMBED_CALL(byteio.put_be, OctetusCfg, .write_span = w,
61 .value = EMBED_CALL(magna_extremitas.rd, EndianCfg, .src = d->
addr.
bytes + 8, .width = MMGR_ENDIAN_64),
78 if (!EMBED_CALL(byteio.take_be, OctetusCfg, .read_span = r, .bytes = 1, .out = &family) ||
79 !EMBED_CALL(byteio.take_be, OctetusCfg, .read_span = r, .bytes = 2, .out = &port) ||
80 !EMBED_CALL(byteio.take_be, OctetusCfg, .read_span = r, .bytes = 2, .out = &len) ||
81 !EMBED_CALL(byteio.take_be, OctetusCfg, .read_span = r, .bytes = 8, .out = &hi) ||
82 !EMBED_CALL(byteio.take_be, OctetusCfg, .read_span = r, .bytes = 8, .out = &lo))
95 (void)EMBED_CALL(magna_extremitas.wr, EndianCfg, .dst = d->
addr.
bytes, .val = hi, .width = MMGR_ENDIAN_64);
96 (void)EMBED_CALL(magna_extremitas.wr, EndianCfg, .dst = d->
addr.
bytes + 8, .val = lo, .width = MMGR_ENDIAN_64);
97 d->
port = (uint16_t)port;
98 d->
len = (uint16_t)len;
110 uint8_t *stage,
size_t stage_cap)
116 EMBED_CALL(anularis.peek, AnularisCfg, .ring = ring, .dst = hdr, .bytes =
PROTOCORE_UDP_DGRAM_HDR, .offset = 0);
122 if (d->
len > stage_cap)
126 EMBED_CALL(anularis.consume, AnularisCfg, .ring = ring,
127 .bytes = EMBED_CALL(anularis.available, AnularisCfg, .ring = ring));
135 (void)EMBED_CALL(anularis.read, AnularisCfg, .ring = ring, .dst = stage, .bytes = d->
len);
#define PROTOCORE_INLINE
Linkage for a leaf primitive whose body is cheaper than the call that reaches it.
Layer 3 (Network) - a family-tagged IP address (IPv4 or IPv6) with RFC-faithful text parsing,...
@ PROTOCORE_IP_NONE
empty / unparsed
@ PROTOCORE_IP_V4
IPv4 (bytes[0..3])
@ PROTOCORE_IP_V6
IPv6 (bytes[0..15])
A v4 or v6 address in network (big-endian) byte order.
uint8_t bytes[16]
network order; v4 uses the first 4
protocore_ip_family family
address family tag
Who a queued datagram is from or to, and how long its payload is.
protocore_ip addr
peer address, network order
uint16_t len
payload bytes following the header
PROTOCORE_INLINE proto_bool protocore_udp_dgram_take(mmgr_ring *ring, uint8_t *hdr, protocore_udp_dgram *d, uint8_t *stage, size_t stage_cap)
Dequeue one datagram: d takes the header, stage takes the payload.
PROTOCORE_INLINE proto_bool protocore_udp_dgram_decode(mmgr_cspan *r, protocore_udp_dgram *d)
Read a header out of r at its cursor into d.
#define PROTOCORE_UDP_DGRAM_HDR
Bytes a queued datagram spends on its header, ahead of the payload.
PROTOCORE_INLINE void protocore_udp_dgram_encode(mmgr_span *w, const protocore_udp_dgram *d)
Write the header of d into w at its cursor.
#define PROTO_FALSE
the false value
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
_Bool proto_bool
The truth value.
#define PROTO_TRUE
the true value, spelled so a caller never writes a bare 1
#define PROTOCORE_END_DECLS