@@ -54,8 +54,10 @@ class IPAddress: public Printable
5454 IPAddress (const IPAddress& from);
5555 IPAddress (uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
5656 IPAddress (uint8_t o1, uint8_t o2, uint8_t o3, uint8_t o4, uint8_t o5, uint8_t o6, uint8_t o7, uint8_t o8, uint8_t o9, uint8_t o10, uint8_t o11, uint8_t o12, uint8_t o13, uint8_t o14, uint8_t o15, uint8_t o16);
57- IPAddress (uint32_t address) { ctor32 (address); }
58- IPAddress (const uint8_t *address); // v4 only
57+ IPAddress (uint32_t address) { *this = address; }
58+ IPAddress (unsigned long address) { *this = address; }
59+ IPAddress (int address) { *this = address; }
60+ IPAddress (const uint8_t *address) { *this = address; }
5961 IPAddress (IPType type, const uint8_t *address);
6062 IPAddress (IPType type, const uint8_t *address, uint8_t zone);
6163
@@ -68,7 +70,7 @@ class IPAddress: public Printable
6870 operator uint32_t () { return isV4 ()? v4 (): (uint32_t )0 ; }
6971
7072 // generic IPv4 wrapper to uint32-view like arduino loves to see it
71- const uint32_t & v4 () const { return ip_2_ip4 (&_ip)->addr ; } // for raw_address(const)
73+ const uint32_t & v4 () const { return ip_2_ip4 (&_ip)->addr ; }
7274 uint32_t & v4 () { return ip_2_ip4 (&_ip)->addr ; }
7375
7476 bool operator ==(const IPAddress& addr) const {
@@ -97,11 +99,16 @@ class IPAddress: public Printable
9799
98100 // Overloaded index operator to allow getting and setting individual octets of the address
99101 uint8_t operator [](int index) const {
100- return isV4 ()? *(raw_address () + index): 0 ;
102+ if (!isV4 ()) {
103+ return 0 ;
104+ }
105+
106+ return ip4_addr_get_byte_val (*ip_2_ip4 (&_ip), index);
101107 }
102108 uint8_t & operator [](int index) {
103109 setV4 ();
104- return *(raw_address () + index);
110+ uint8_t * ptr = reinterpret_cast <uint8_t *>(&v4 ());
111+ return *(ptr + index);
105112 }
106113
107114 // Overloaded copy operators to allow initialisation of IPAddress objects from other types
0 commit comments