@@ -54,8 +54,10 @@ class IPAddress: public Printable
54
54
IPAddress (const IPAddress& from);
55
55
IPAddress (uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
56
56
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; }
59
61
IPAddress (IPType type, const uint8_t *address);
60
62
IPAddress (IPType type, const uint8_t *address, uint8_t zone);
61
63
@@ -68,7 +70,7 @@ class IPAddress: public Printable
68
70
operator uint32_t () { return isV4 ()? v4 (): (uint32_t )0 ; }
69
71
70
72
// 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 ; }
72
74
uint32_t & v4 () { return ip_2_ip4 (&_ip)->addr ; }
73
75
74
76
bool operator ==(const IPAddress& addr) const {
@@ -97,11 +99,16 @@ class IPAddress: public Printable
97
99
98
100
// Overloaded index operator to allow getting and setting individual octets of the address
99
101
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 );
101
107
}
102
108
uint8_t & operator [](int index) {
103
109
setV4 ();
104
- return *(raw_address () + index );
110
+ uint8_t * ptr = reinterpret_cast <uint8_t *>(&v4 ());
111
+ return *(ptr + index );
105
112
}
106
113
107
114
// Overloaded copy operators to allow initialisation of IPAddress objects from other types
0 commit comments