@@ -61,19 +61,16 @@ class IPAddress: public Printable {
6161 return reinterpret_cast <const uint8_t *>(&v4 ());
6262 }
6363
64- void ctor32 (uint32_t );
65-
6664 public:
67- // Constructors
6865 IPAddress ();
6966 IPAddress (const IPAddress&);
7067 IPAddress (IPAddress&&);
7168
7269 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; }
7774
7875 bool fromString (const char *address);
7976 bool fromString (const String &address) { return fromString (address.c_str ()); }
@@ -88,7 +85,7 @@ class IPAddress: public Printable {
8885 operator bool () { return isSet (); } // <- both are needed
8986
9087 // 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 ; }
9289 uint32_t & v4 () { return ip_2_ip4 (&_ip)->addr ; }
9390
9491 bool operator ==(const IPAddress& addr) const {
@@ -117,11 +114,18 @@ class IPAddress: public Printable {
117114
118115 // Overloaded index operator to allow getting and setting individual octets of the address
119116 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);
121122 }
123+
122124 uint8_t & operator [](int index) {
123125 setV4 ();
124- return *(raw_address () + index);
126+
127+ uint8_t * ptr = reinterpret_cast <uint8_t *>(&v4 ());
128+ return *(ptr + index);
125129 }
126130
127131 // Overloaded copy operators to allow initialisation of IPAddress objects from other types
0 commit comments