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>
59static inline int ipaddr_aton(
const char *cp,
ip_addr_t *addr) {
return inet_pton(AF_INET6, cp, addr) == 1 ? 1 : 0; }
62#if USE_ESP32_FRAMEWORK_ARDUINO
63#define arduino_ns Arduino_h
65#define arduino_ns arduino
77static constexpr size_t IP_ADDRESS_BUFFER_SIZE = 40;
81 for (
char *p = buf; *p; ++p) {
82 if (*p >=
'A' && *p <=
'F')
95 operator struct in6_addr() const {
return ip_addr_; }
98 bool is_ip4()
const {
return false; }
102 if (inet_ntop(AF_INET6, &
ip_addr_, buf, IP_ADDRESS_BUFFER_SIZE) ==
nullptr)
109#elif defined(USE_HOST)
120 ipaddr_aton(in_address, &this->
ip_addr_);
137 static constexpr uint8_t zero[
sizeof(
struct in6_addr)] = {};
152 "str() is deprecated: use 'char buf[IP_ADDRESS_BUFFER_SIZE]; ip.str_to(buf);' instead. Removed in 2026.8.0",
154 std::
string str()
const {
155 char buf[IP_ADDRESS_BUFFER_SIZE];
159 char *
str_to(
char *buf)
const {
173 return memcmp(&this->
ip_addr_.
u_addr.
ip6, &other.ip_addr_.u_addr.ip6,
sizeof(
struct in6_addr)) == 0;
187 this->
ip_addr_.s_addr = htonl((first << 24) | (
second << 16) | (third << 8) | fourth);
193 inet_ntop(AF_INET, &
ip_addr_, buf, IP_ADDRESS_BUFFER_SIZE);
224 memcpy((
void *) &
ip_addr_.
u_addr.
ip6, (
void *) other_ip,
sizeof(esp_ip6_addr_t));
229 memcpy((
void *) &
ip_addr_, (
void *) other_ip,
sizeof(esp_ip4_addr_t));
241 operator esp_ip_addr_t()
const {
250 operator esp_ip4_addr_t()
const {
267 operator arduino_ns::IPAddress()
const {
return ip_addr_get_ip4_u32(&
ip_addr_); }
277 ipaddr_ntoa_r(&
ip_addr_, buf, IP_ADDRESS_BUFFER_SIZE);
288 (((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
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
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::@146 u_addr
struct in6_addr sin6_addr