hosts.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2025 ML!PA Consulting GmbH
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
60 #include "flash_utils.h"
61 #include "net/ipv4/addr.h"
62 #include "net/ipv6/addr.h"
63 #include "xfa.h"
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #else
68 
74 typedef struct {
75  FLASH_ATTR const char *name;
76  const ipv4_addr_t addr;
78 
84 typedef struct {
85  FLASH_ATTR const char *name;
86  const ipv6_addr_t addr;
88 
105 #define HOST_IPV4(host, ip) \
106  XFA_USE_CONST(hostnames_v4_xfa_t, hostnames_v4_xfa); \
107  static FLASH_ATTR const char _xfa_ ## host ## _hostname[] = #host; \
108  XFA_CONST(hostnames_v4_xfa_t, hostnames_v4_xfa, 0) _xfa_ ## host ## _host = { \
109  .name = _xfa_ ## host ## _hostname, \
110  .addr = ip, \
111  };
112 
129 #define HOST_IPV6(host, ip) \
130  XFA_USE_CONST(hostnames_v6_xfa_t, hostnames_v6_xfa); \
131  static FLASH_ATTR const char _xfa_ ## host ## _hostname[] = #host; \
132  XFA_CONST(hostnames_v6_xfa_t, hostnames_v6_xfa, 0) _xfa_ ## host ## _host = { \
133  .name = _xfa_ ## host ## _hostname, \
134  .addr = ip, \
135  };
136 #endif /* __cplusplus */
137 
153 int hosts_query(const char *host_name, void *addr_out, int family);
154 
155 #ifdef __cplusplus
156 }
157 #endif
158 
Utility functions, macros, and types for read-only memory.
int hosts_query(const char *host_name, void *addr_out, int family)
Get IP address for a host name.
#define FLASH_ATTR
C type qualifier required to place a variable in flash.
Definition: flash_utils.h:67
IPv4 address type and helper functions definitions.
Definitions for IPv6 addresses.
A single IPv4 host in the list of hostnames.
Definition: hosts.h:74
FLASH_ATTR const char * name
Name of the host
Definition: hosts.h:75
const ipv4_addr_t addr
Address of the host.
Definition: hosts.h:76
A single IPv6 host in the list of hostnames.
Definition: hosts.h:84
FLASH_ATTR const char * name
Name of the host
Definition: hosts.h:85
const ipv6_addr_t addr
Address of the host.
Definition: hosts.h:86
Data type to represent an IPv4 address.
Definition: addr.h:58
Data type to represent an IPv6 address.
Definition: addr.h:67
Cross File Arrays.