@@ -61,19 +61,16 @@ class IPAddress: public Printable {
61
61
return reinterpret_cast <const uint8_t *>(&v4 ());
62
62
}
63
63
64
- void ctor32 (uint32_t );
65
-
66
64
public:
67
- // Constructors
68
65
IPAddress ();
69
66
IPAddress (const IPAddress&);
70
67
IPAddress (IPAddress&&);
71
68
72
69
IPAddress (uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
73
- IPAddress (uint32_t address) { ctor32 ( address) ; }
74
- IPAddress (unsigned long address) { ctor32 ( address) ; }
75
- IPAddress (int address) { ctor32 ( address) ; }
76
- IPAddress (const uint8_t *address);
70
+ IPAddress (uint32_t address) { * this = address; }
71
+ IPAddress (unsigned long address) { * this = address; }
72
+ IPAddress (int address) { * this = address; }
73
+ IPAddress (const uint8_t *address) { * this = address; }
77
74
78
75
bool fromString (const char *address);
79
76
bool fromString (const String &address) { return fromString (address.c_str ()); }
@@ -88,7 +85,7 @@ class IPAddress: public Printable {
88
85
operator bool () { return isSet (); } // <- both are needed
89
86
90
87
// generic IPv4 wrapper to uint32-view like arduino loves to see it
91
- const uint32_t & v4 () const { return ip_2_ip4 (&_ip)->addr ; } // for raw_address(const)
88
+ const uint32_t & v4 () const { return ip_2_ip4 (&_ip)->addr ; }
92
89
uint32_t & v4 () { return ip_2_ip4 (&_ip)->addr ; }
93
90
94
91
bool operator ==(const IPAddress& addr) const {
@@ -117,11 +114,18 @@ class IPAddress: public Printable {
117
114
118
115
// Overloaded index operator to allow getting and setting individual octets of the address
119
116
uint8_t operator [](int index) const {
120
- return isV4 ()? *(raw_address () + index ): 0 ;
117
+ if (!isV4 ()) {
118
+ return 0 ;
119
+ }
120
+
121
+ return ip4_addr_get_byte_val (*ip_2_ip4 (&_ip), index );
121
122
}
123
+
122
124
uint8_t & operator [](int index) {
123
125
setV4 ();
124
- return *(raw_address () + index );
126
+
127
+ uint8_t * ptr = reinterpret_cast <uint8_t *>(&v4 ());
128
+ return *(ptr + index );
125
129
}
126
130
127
131
// Overloaded copy operators to allow initialisation of IPAddress objects from other types
0 commit comments