VSF Documented
esp_netif_ip_addr.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*
19 * Clean-room re-implementation of ESP-IDF public API "esp_netif_ip_addr.h".
20 *
21 * Authored from ESP-IDF v5.x public API only. No code copied from the
22 * ESP-IDF source tree. Addresses are stored in network byte order to match
23 * the ESP-IDF contract; helper macros mirror the upstream names.
24 */
25
26#ifndef __VSF_ESPIDF_ESP_NETIF_IP_ADDR_H__
27#define __VSF_ESPIDF_ESP_NETIF_IP_ADDR_H__
28
29#include <stdint.h>
30#include <stdbool.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/*============================ TYPES =========================================*/
37
38/* IPv4 address in network byte order. */
39typedef struct esp_ip4_addr {
42
43/* IPv6 address in network byte order. zone is the IPv6 scope id
44 * (0 when unscoped). */
45typedef struct esp_ip6_addr {
49
50/* Tagged union covering both address families. type is one of the
51 * ESP_IPADDR_TYPE_* constants below. */
52typedef struct esp_ip_addr {
53 union {
59
60/* Address family tag values for esp_ip_addr_t::type. */
61#define ESP_IPADDR_TYPE_V4 0U
62#define ESP_IPADDR_TYPE_V6 6U
63#define ESP_IPADDR_TYPE_ANY 46U
64
65/*============================ MACROS ========================================*/
66
67/* Build an esp_ip4_addr_t from four dotted-decimal octets (host-order args,
68 * stored in network byte order). Matches ESP-IDF ESP_IP4TOADDR semantics. */
69#define ESP_IP4TOUINT32(a, b, c, d) \
70 (((uint32_t)((a) & 0xff)) | \
71 ((uint32_t)((b) & 0xff) << 8) | \
72 ((uint32_t)((c) & 0xff) << 16) | \
73 ((uint32_t)((d) & 0xff) << 24))
74
75#define ESP_IP4TOADDR(a, b, c, d) ESP_IP4TOUINT32(a, b, c, d)
76
77/* Copy a raw 32-bit (network-order) IPv4 value into an esp_ip4_addr_t. */
78#define ESP_IP4ADDR(ipaddr, a, b, c, d) \
79 do { \
80 (ipaddr)->addr = ESP_IP4TOADDR(a, b, c, d); \
81 } while (0)
82
83/* Extract an octet from a network-order IPv4 address. The _n form reads the
84 * byte at offset n (0 is the lowest-order byte of the network value). */
85#define esp_ip4_addr1(ipaddr) ((uint8_t)((ipaddr)->addr & 0xff))
86#define esp_ip4_addr2(ipaddr) ((uint8_t)(((ipaddr)->addr >> 8) & 0xff))
87#define esp_ip4_addr3(ipaddr) ((uint8_t)(((ipaddr)->addr >> 16) & 0xff))
88#define esp_ip4_addr4(ipaddr) ((uint8_t)(((ipaddr)->addr >> 24) & 0xff))
89
90/* printf helper: expands to "%u.%u.%u.%u" argument tuple. */
91#define IPSTR "%u.%u.%u.%u"
92#define IP2STR(ipaddr) \
93 esp_ip4_addr1(ipaddr), \
94 esp_ip4_addr2(ipaddr), \
95 esp_ip4_addr3(ipaddr), \
96 esp_ip4_addr4(ipaddr)
97
98#ifdef __cplusplus
99}
100#endif
101
102#endif // __VSF_ESPIDF_ESP_NETIF_IP_ADDR_H__
struct esp_ip4_addr esp_ip4_addr_t
struct esp_ip_addr esp_ip_addr_t
struct esp_ip6_addr esp_ip6_addr_t
unsigned uint32_t
Definition stdint.h:9
unsigned char uint8_t
Definition stdint.h:5
Definition esp_netif_ip_addr.h:39
uint32_t addr
Definition esp_netif_ip_addr.h:40
Definition esp_netif_ip_addr.h:45
uint8_t zone
Definition esp_netif_ip_addr.h:47
uint32_t addr[4]
Definition esp_netif_ip_addr.h:46
Definition esp_netif_ip_addr.h:52
esp_ip6_addr_t ip6
Definition esp_netif_ip_addr.h:54
esp_ip4_addr_t ip4
Definition esp_netif_ip_addr.h:55
uint8_t type
Definition esp_netif_ip_addr.h:57
union esp_ip_addr::@990 u_addr
Generated from commit: vsfteam/vsf@015f4d1