12#if defined(USE_ESP32) || defined(USE_LIBRETINY) || USE_ARDUINO_VERSION_CODE > VERSION_CODE(3, 0, 0)
13#include <lwip/ip_addr.h>
24#define ipaddr_aton(x, y) inet_aton((x), (y))
28#include <zephyr/net/net_ip.h>
29#include <zephyr/net/socket.h>
30#include <zephyr/posix/arpa/inet.h>
32static inline int ipaddr_aton(
const char *cp,
ip_addr_t *addr) {
return inet_pton(AF_INET6, cp, addr) == 1 ? 1 : 0; }
35#if USE_ESP32_FRAMEWORK_ARDUINO
36#define arduino_ns Arduino_h
38#define arduino_ns arduino
50static constexpr size_t IP_ADDRESS_BUFFER_SIZE = 40;
54 for (
char *p = buf; *p; ++p) {
55 if (*p >=
'A' && *p <=
'F')
68 operator struct in6_addr() const {
return ip_addr_; }
71 bool is_ip4()
const {
return false; }
76 "str() is deprecated: use 'char buf[IP_ADDRESS_BUFFER_SIZE]; ip.str_to(buf);' instead. Removed in 2026.8.0",
78 std::
string str()
const {
79 char buf[IP_ADDRESS_BUFFER_SIZE];
83 char *str_to(
char *buf)
const {
84 if (inet_ntop(AF_INET6, &
ip_addr_, buf, IP_ADDRESS_BUFFER_SIZE) ==
nullptr)
91#elif defined(USE_HOST)
94 this->
ip_addr_.s_addr = htonl((first << 24) | (
second << 16) | (third << 8) | fourth);
100 "str() is deprecated: use 'char buf[IP_ADDRESS_BUFFER_SIZE]; ip.str_to(buf);' instead. Removed in 2026.8.0",
102 std::
string str()
const {
103 char buf[IP_ADDRESS_BUFFER_SIZE];
108 char *str_to(
char *buf)
const {
109 inet_ntop(AF_INET, &
ip_addr_, buf, IP_ADDRESS_BUFFER_SIZE);
122#if USE_ESP32 && LWIP_IPV6
131 memcpy((
void *) &
ip_addr_, (
void *) other_ip,
sizeof(ip6_addr_t));
139 memcpy((
void *) &
ip_addr_.u_addr.ip6, (
void *) other_ip,
sizeof(esp_ip6_addr_t));
144 memcpy((
void *) &
ip_addr_, (
void *) other_ip,
sizeof(esp_ip4_addr_t));
153 memcpy((
void *) &
ip_addr_, (
void *) &other_ip->u_addr.ip4,
sizeof(
ip_addr_));
156 operator esp_ip_addr_t()
const {
165 operator esp_ip4_addr_t()
const {
168 memcpy((
void *) &tmp, (
void *) &
ip_addr_.u_addr.ip4,
sizeof(esp_ip4_addr_t));
182 operator arduino_ns::IPAddress()
const {
return ip_addr_get_ip4_u32(&
ip_addr_); }
191 "str() is deprecated: use 'char buf[IP_ADDRESS_BUFFER_SIZE]; ip.str_to(buf);' instead. Removed in 2026.8.0",
193 std::
string str()
const {
194 char buf[IP_ADDRESS_BUFFER_SIZE];
200 char *str_to(
char *buf)
const {
201 ipaddr_ntoa_r(&
ip_addr_, buf, IP_ADDRESS_BUFFER_SIZE);
210 (((u8_t *) (&
ip_addr_.u_addr.ip4))[3]) += increase;
212 (((u8_t *) (&
ip_addr_.addr))[3]) += increase;
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 operator!=(const StringRef &lhs, const StringRef &rhs)
std::string & operator+=(std::string &lhs, const StringRef &rhs)
bool operator==(const StringRef &lhs, const StringRef &rhs)
bool is_multicast() const
IPAddress(const struct sockaddr_in6 *addr)
IPAddress(const char *in_address)
IPAddress(ip6_addr_t *other_ip)
ESPDEPRECATED("str() is deprecated: use 'char buf[IP_ADDRESS_BUFFER_SIZE]; ip.str_to(buf);' instead. Removed in 2026.8.0", "2026.2.0") std
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(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)
struct in6_addr sin6_addr