ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
ip.h File Reference

Layer 3 (Network) - a family-tagged IP address (IPv4 or IPv6) with RFC-faithful text parsing, canonical formatting, and scope classification. More...

#include "protocore_config.h"

Go to the source code of this file.

Classes

struct  protocore_ip
 A v4 or v6 address in network (big-endian) byte order. More...
 
struct  IpArgs
 True if ip is empty (PROTOCORE_IP_NONE) or the all-zero unspecified address (0.0.0.0 / ::). More...
 
struct  IpVars
 
struct  IpNs
 The entries. More...
 

Macros

#define PROTOCORE_IP_STR_MAX   46
 Longest text an IpNs::format can produce, including the NUL (RFC 5952 v4-mapped).
 

Typedefs

typedef PROTOCORE_BEGIN_DECLS enum PROTO_ENUM_PACKED protocore_ip_family
 Address family tag.
 
typedef enum PROTO_ENUM_PACKED protocore_ip_scope
 Address scope, in rough order of reachability (used for allow/deny policy + logging).
 
typedef struct protocore_ip protocore_ip
 A v4 or v6 address in network (big-endian) byte order.
 

Enumerations

enum  PROTO_ENUM_PACKED {
  PROTOCORE_IP_NONE = 0 , PROTOCORE_IP_V4 = 4 , PROTOCORE_IP_V6 = 6 , PROTOCORE_IP_SCOPE_UNSPECIFIED = 0 ,
  PROTOCORE_IP_SCOPE_LOOPBACK , PROTOCORE_IP_SCOPE_LINK_LOCAL , PROTOCORE_IP_SCOPE_PRIVATE , PROTOCORE_IP_SCOPE_MULTICAST ,
  PROTOCORE_IP_SCOPE_GLOBAL
}
 Address family tag. More...
 
enum  PROTO_ENUM_PACKED {
  PROTOCORE_IP_NONE = 0 , PROTOCORE_IP_V4 = 4 , PROTOCORE_IP_V6 = 6 , PROTOCORE_IP_SCOPE_UNSPECIFIED = 0 ,
  PROTOCORE_IP_SCOPE_LOOPBACK , PROTOCORE_IP_SCOPE_LINK_LOCAL , PROTOCORE_IP_SCOPE_PRIVATE , PROTOCORE_IP_SCOPE_MULTICAST ,
  PROTOCORE_IP_SCOPE_GLOBAL
}
 Address scope, in rough order of reachability (used for allow/deny policy + logging). More...
 

Functions

proto_bool protocore_ip_is_v4_mapped (const protocore_ip *ip)
 Parse an IPv4 or IPv6 textual address (RFC 4291 §2.2) into out.
 
protocore_ip protocore_ip_from_v4_octets (uint8_t a, uint8_t b, uint8_t c, uint8_t d)
 Build a v4 protocore_ip from four octets (a.b.c.d).
 
protocore_ip protocore_ip_from_v6_bytes (const uint8_t bytes[16])
 Build a v6 protocore_ip from 16 address bytes in network (big-endian) order.
 
uint32_t protocore_ip_to_v4_be (const protocore_ip *ip)
 The v4 address as a big-endian (network-order) uint32 (a<<24 | b<<16 | c<<8 | d).
 
void protocore_ip_parse (uint8_t *work)
 
void protocore_ip_format (uint8_t *work)
 
void protocore_ip_classify (uint8_t *work)
 
void protocore_ip_equal (uint8_t *work)
 
void protocore_ip_is_unspecified (uint8_t *work)
 
void protocore_ip_prefix_match (uint8_t *work)
 

Variables

IpVars IpV
 The operands and the outcome.
 

Detailed Description

Layer 3 (Network) - a family-tagged IP address (IPv4 or IPv6) with RFC-faithful text parsing, canonical formatting, and scope classification.

One representation for both address families so the rest of the stack can carry a peer address without caring whether it is v4 or v6. The address bytes are stored in network (big-endian, left-to-right) order: a v4 address uses bytes[0..3], a v6 address bytes[0..15].

Pure and host-testable - no lwIP, no Arduino, no heap, no stdlib parsing. The parser implements RFC 4291 §2.2 text forms (dotted-quad v4; v6 with :: zero-compression and the embedded-v4 ::ffff:a.b.c.d tail); the formatter emits the RFC 5952 canonical form (lower-case, no leading zeros, the longest zero run compressed to ::, v4-mapped shown as dotted). ESP32 dual-stack bring-up (enabling IPv6 on the netif) lives in the physical layer behind PROTOCORE_ENABLE_IPV6; the TCP/UDP listeners already bind IPADDR_TYPE_ANY, so the server accepts v6 connections the moment the interface has a v6 address.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file ip.h.

Macro Definition Documentation

◆ PROTOCORE_IP_STR_MAX

#define PROTOCORE_IP_STR_MAX   46

Longest text an IpNs::format can produce, including the NUL (RFC 5952 v4-mapped).

Definition at line 62 of file ip.h.

Typedef Documentation

◆ protocore_ip_family

◆ protocore_ip_scope

Address scope, in rough order of reachability (used for allow/deny policy + logging).

◆ protocore_ip

typedef struct protocore_ip protocore_ip

A v4 or v6 address in network (big-endian) byte order.

Enumeration Type Documentation

◆ PROTO_ENUM_PACKED [1/2]

Address family tag.

Enumerator
PROTOCORE_IP_NONE 

empty / unparsed

PROTOCORE_IP_V4 

IPv4 (bytes[0..3])

PROTOCORE_IP_V6 

IPv6 (bytes[0..15])

PROTOCORE_IP_SCOPE_UNSPECIFIED 

0.0.0.0 / ::

PROTOCORE_IP_SCOPE_LOOPBACK 

127.0.0.0/8 / ::1

PROTOCORE_IP_SCOPE_LINK_LOCAL 

169.254.0.0/16 / fe80::/10

PROTOCORE_IP_SCOPE_PRIVATE 

RFC1918 (10/8, 172.16/12, 192.168/16) / ULA fc00::/7.

PROTOCORE_IP_SCOPE_MULTICAST 

224.0.0.0/4 / ff00::/8

PROTOCORE_IP_SCOPE_GLOBAL 

globally routable unicast

Definition at line 33 of file ip.h.

◆ PROTO_ENUM_PACKED [2/2]

Address scope, in rough order of reachability (used for allow/deny policy + logging).

Enumerator
PROTOCORE_IP_NONE 

empty / unparsed

PROTOCORE_IP_V4 

IPv4 (bytes[0..3])

PROTOCORE_IP_V6 

IPv6 (bytes[0..15])

PROTOCORE_IP_SCOPE_UNSPECIFIED 

0.0.0.0 / ::

PROTOCORE_IP_SCOPE_LOOPBACK 

127.0.0.0/8 / ::1

PROTOCORE_IP_SCOPE_LINK_LOCAL 

169.254.0.0/16 / fe80::/10

PROTOCORE_IP_SCOPE_PRIVATE 

RFC1918 (10/8, 172.16/12, 192.168/16) / ULA fc00::/7.

PROTOCORE_IP_SCOPE_MULTICAST 

224.0.0.0/4 / ff00::/8

PROTOCORE_IP_SCOPE_GLOBAL 

globally routable unicast

Definition at line 43 of file ip.h.

Function Documentation

◆ protocore_ip_is_v4_mapped()

proto_bool protocore_ip_is_v4_mapped ( const protocore_ip *  ip)

Parse an IPv4 or IPv6 textual address (RFC 4291 §2.2) into out.

Returns
true on success (out->family set to PROTOCORE_IP_V4/V6), false if s is malformed.

Format ip into out as its RFC 5952 canonical text.

Returns
the length written (excluding the NUL), or 0 if ip is empty or cap is too small (need up to PROTOCORE_IP_STR_MAX).

Classify ip into a protocore_ip_scope.

True if a and b are the same family and address.

True if ip is an IPv4-mapped IPv6 address (::ffff:a.b.c.d, RFC 4291 §2.5.5.2).

◆ protocore_ip_from_v4_octets()

protocore_ip protocore_ip_from_v4_octets ( uint8_t  a,
uint8_t  b,
uint8_t  c,
uint8_t  d 
)

Build a v4 protocore_ip from four octets (a.b.c.d).

◆ protocore_ip_from_v6_bytes()

protocore_ip protocore_ip_from_v6_bytes ( const uint8_t  bytes[16])

Build a v6 protocore_ip from 16 address bytes in network (big-endian) order.

◆ protocore_ip_to_v4_be()

uint32_t protocore_ip_to_v4_be ( const protocore_ip *  ip)

The v4 address as a big-endian (network-order) uint32 (a<<24 | b<<16 | c<<8 | d).

Returns
0 if ip is not a v4 (or v4-mapped) address.

◆ protocore_ip_parse()

void protocore_ip_parse ( uint8_t *  work)

◆ protocore_ip_format()

void protocore_ip_format ( uint8_t *  work)

◆ protocore_ip_classify()

void protocore_ip_classify ( uint8_t *  work)

◆ protocore_ip_equal()

void protocore_ip_equal ( uint8_t *  work)

◆ protocore_ip_is_unspecified()

void protocore_ip_is_unspecified ( uint8_t *  work)

◆ protocore_ip_prefix_match()

void protocore_ip_prefix_match ( uint8_t *  work)

Variable Documentation

◆ IpV

IpVars IpV
extern

The operands and the outcome.