ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
net_addr.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file net_addr.h
6 * @brief Layer 4 (Transport) - the stack's address type, as the library's ::protocore_ip.
7 *
8 * The stack keeps a peer address in its own family-tagged union, laid out however the vendor chose.
9 * Everything above the transport carries a ::protocore_ip: a one-byte family tag and sixteen bytes in
10 * network order, the same on every target. TCP needs that mapping on accept and on the per-slot
11 * address accessor; UDP needs it once per received datagram. One conversion serves both, so it sits
12 * beside them rather than inside either.
13 *
14 * RFC 9293 sec 3.9.2: "Any lower-level protocol will have to provide the source address,
15 * destination address, and protocol fields." These two convert between the form the lower-level
16 * module states them in and the family-tagged form every layer above reads.
17 *
18 * The address bytes are read out of the vendor value byte by byte rather than shifted out of it. A
19 * shift reads the value's arithmetic, which is the host's byte order; the stack holds the address in
20 * network order, so the bytes are the address and the number is not.
21 *
22 * @author Douglas Quigg (dstroy0)
23 * @date 2026
24 */
25
26#ifndef PROTOCORE_NET_ADDR_H
27#define PROTOCORE_NET_ADDR_H
28
29#include "config/platform/platform.h" // protocore_net_ip: the stack's own address type
30#include "shared/ip/ip.h" // protocore_ip: the address everything above carries
31
32#include "protocore_config.h"
33
35
36/** @brief Inbound: the stack's address, and the library address it lands in. */
37typedef struct
38{
39 const protocore_net_ip *addr; ///< the stack's address a read starts from
40 protocore_ip *out_ip; ///< where a read lands
42
43/** @brief Outbound: the library address, and the stack address it lands in. */
44typedef struct
45{
46 const protocore_ip *ip; ///< the library address a write starts from
47 protocore_net_ip *out_addr; ///< where a write lands
49
50/**
51 * @brief The stack's address, as the library's address.
52 *
53 * A caller sets the members a call takes, invokes it through ::NetAddr, and reads the outcome off
54 * the same handle.
55 *
56 * @var NetAddrNs::in what a read carries across
57 * @var NetAddrNs::out what a write carries across
58 * @var NetAddrNs::ok whether the address could be represented
59 * @var NetAddrNs::to_ip read @c in.addr into @c in.out_ip, network-order bytes preserved
60 * @var NetAddrNs::from_ip write @c out.ip into @c out.out_addr, ready to hand to a send; false when the
61 * address names a family this stack cannot send to
62 *
63 * Both families cross both ways. IPv6 is carried where the stack has it (::PROTOCORE_NET_HAS_IPV6); where
64 * it does not, a v6 address converts to nothing rather than to a wrong v4.
65 *
66 * No storage member: the conversions read their operands and hold nothing.
67 */
68typedef struct
69{
70 NetAddrInArgs in; ///< what a read carries across
71 NetAddrOutArgs out; ///< what a write carries across
72
74
75 void (*const to_ip)(uint8_t *work);
76 void (*const from_ip)(uint8_t *work);
77} NetAddrNs;
78
79/** @brief The one symbol this module exports. */
80extern NetAddrNs NetAddr;
81
82/** @brief Read the stack's address into @p out, network-order bytes preserved. */
83void protocore_net_addr_to_ip(const protocore_net_ip *a, protocore_ip *out);
84
85/** @brief Write @p a into the stack's own address type; false when it cannot be represented. */
86proto_bool protocore_net_addr_from_ip(const protocore_ip *a, protocore_net_ip *out);
87
89
90#endif // PROTOCORE_NET_ADDR_H
Layer 3 (Network) - a family-tagged IP address (IPv4 or IPv6) with RFC-faithful text parsing,...
void protocore_net_addr_to_ip(const protocore_net_ip *a, protocore_ip *out)
Read the stack's address into out, network-order bytes preserved.
NetAddrNs NetAddr
The one symbol this module exports.
proto_bool protocore_net_addr_from_ip(const protocore_ip *a, protocore_net_ip *out)
Write a into the stack's own address type; false when it cannot be represented.
The platform contract: what the library asks of a target, in the library's own words.
Inbound: the stack's address, and the library address it lands in.
Definition net_addr.h:38
protocore_ip * out_ip
where a read lands
Definition net_addr.h:40
const protocore_net_ip * addr
the stack's address a read starts from
Definition net_addr.h:39
NetAddrOutArgs out
what a write carries across
Definition net_addr.h:71
proto_bool ok
Definition net_addr.h:73
NetAddrInArgs in
what a read carries across
Definition net_addr.h:70
Outbound: the library address, and the stack address it lands in.
Definition net_addr.h:45
const protocore_ip * ip
the library address a write starts from
Definition net_addr.h:46
protocore_net_ip * out_addr
where a write lands
Definition net_addr.h:47
A v4 or v6 address in network (big-endian) byte order.
Definition ip.h:56
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
_Bool proto_bool
The truth value.
Definition types.h:64
#define PROTOCORE_END_DECLS
Definition types.h:97