12#if defined(USE_ESP32) || defined(USE_LIBRETINY) || USE_ARDUINO_VERSION_CODE > VERSION_CODE(3, 0, 0)
13#include <lwip/ip_addr.h>
33static inline int ipaddr_aton(
const char *cp,
ip_addr_t *addr) {
34 if (strchr(cp,
':') !=
nullptr) {
35 if (inet_pton(AF_INET6, cp, &addr->
u_addr.
ip6) != 1) {
41 if (inet_aton(cp, &addr->
u_addr.
ip4) != 1) {
50#define ipaddr_aton(x, y) inet_aton((x), (y))
55#include <zephyr/net/net_ip.h>
56#include <zephyr/net/socket.h>
57#include <zephyr/posix/arpa/inet.h>
58#ifndef CONFIG_NET_IPV6
59#error "Zephyr builds need CONFIG_NET_IPV6"
62static inline int ipaddr_aton(
const char *cp,
ip_addr_t *addr) {
63#if defined(CONFIG_NET_IPV4)
67 if (inet_pton(AF_INET, cp, &addr4) == 1) {
68 net_ipv6_addr_create_v4_mapped(&addr4, addr);
72 return inet_pton(AF_INET6, cp, addr) == 1 ? 1 : 0;
76#if USE_ESP32_FRAMEWORK_ARDUINO
77#define arduino_ns Arduino_h
79#define arduino_ns arduino
91static constexpr size_t IP_ADDRESS_BUFFER_SIZE =
92#if defined(USE_ZEPHYR)
103 for (
char *p = buf; *p; ++p) {
104 if (*p >=
'A' && *p <=
'F')
111#if defined(USE_ZEPHYR)
114#if defined(CONFIG_NET_IPV4)
116 struct in_addr addr4{
118 net_ipv6_addr_create_v4_mapped(&addr4, &
ip_addr_);
125 operator struct in6_addr() const {
return ip_addr_; }
128#if defined(CONFIG_NET_IPV4)
129 if (net_ipv6_addr_is_v4_mapped(&
ip_addr_))
132 return !net_ipv6_is_addr_unspecified(&
ip_addr_);
134#if defined(CONFIG_NET_IPV4)
144#if defined(CONFIG_NET_IPV4)
145 if (net_ipv6_addr_is_v4_mapped(&
ip_addr_)) {
146 struct in_addr addr4{};
147 addr4.s_addr =
ip_addr_.s6_addr32[3];
148 return net_ipv4_is_addr_mcast(&addr4);
151 return net_ipv6_is_addr_mcast(&
ip_addr_);
154#if defined(CONFIG_NET_IPV4)
156 struct in_addr addr4{};
157 addr4.s_addr =
ip_addr_.s6_addr32[3];
158 if (inet_ntop(AF_INET, &addr4, buf, IP_ADDRESS_BUFFER_SIZE) ==
nullptr)
163 if (inet_ntop(AF_INET6, &
ip_addr_, buf, IP_ADDRESS_BUFFER_SIZE) ==
nullptr)
170#elif defined(USE_HOST)
181 ipaddr_aton(in_address, &this->
ip_addr_);
198 static constexpr uint8_t ZERO[
sizeof(
struct in6_addr)] = {};
239 this->
ip_addr_.s_addr = htonl((first << 24) | (
second << 16) | (third << 8) | fourth);
247 inet_ntop(AF_INET, &
ip_addr_, buf, IP_ADDRESS_BUFFER_SIZE);
282 memcpy((
void *) ip_2_ip6(&
ip_addr_), (
void *) other_ip,
sizeof(esp_ip6_addr_t));
288 memcpy((
void *) &
ip_addr_, (
void *) other_ip,
sizeof(esp_ip4_addr_t));
301 operator esp_ip_addr_t()
const {
312#error "Neither LWIP_IPV4 nor LWIP_IPV6 is enabled"
317 operator esp_ip4_addr_t()
const {
330#if LWIP_IPV6 && LWIP_IPV4
335 operator arduino_ns::IPAddress()
const {
return ip_addr_get_ip4_u32(&
ip_addr_); }
345 ipaddr_ntoa_r(&
ip_addr_, buf, IP_ADDRESS_BUFFER_SIZE);
357 (((u8_t *) (&
ip_addr_.addr))[3]) += increase;
struct in6_addr ip6_addr_t
struct in_addr ip4_addr_t
void lowercase_ip_str(char *buf)
Lowercase hex digits in IP address string (A-F -> a-f for IPv6 per RFC 5952)
std::array< IPAddress, 5 > IPAddresses
bool is_multicast() const
IPAddress(const struct sockaddr_in6 *addr)
IPAddress(const char *in_address)
IPAddress(ip6_addr_t *other_ip)
bool operator!=(const IPAddress &other) const
bool operator==(const IPAddress &other) const
char * str_to(char *buf) const
IPAddress(esp_ip_addr_t *other_ip)
IPAddress(const ip_addr_t *other_ip)
IPAddress(esp_ip6_addr_t *other_ip)
IPAddress(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth)
IPAddress(const struct in6_addr *other_ip)
IPAddress & operator+=(uint8_t increase)
IPAddress(esp_ip4_addr_t *other_ip)
IPAddress(ip4_addr_t *other_ip)
IPAddress(const std::string &in_address)
IPAddress(const arduino_ns::IPAddress &other_ip)
union ip_addr_t::@150 u_addr
struct in6_addr sin6_addr