|
-
-
- #ifndef IPAddress_h
- #define IPAddress_h
-
- #include <Printable.h>
- #include <WString.h>
-
-
-
- class IPAddress : public Printable {
- private:
- union {
- uint8_t bytes[4];
- uint32_t dword;
- } _address;
-
-
-
-
-
- uint8_t * raw_address() { return _address.bytes; };
-
- public:
-
- IPAddress() {
- _address.dword = 0;
- }
- IPAddress(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) {
- _address.bytes[0] = b1;
- _address.bytes[1] = b2;
- _address.bytes[2] = b3;
- _address.bytes[3] = b4;
- }
- IPAddress(uint32_t address) {
- _address.dword = address;
- }
- IPAddress(const uint8_t *address) {
-
- _address.bytes[0] = *address++;
- _address.bytes[1] = *address++;
- _address.bytes[2] = *address++;
- _address.bytes[3] = *address++;
- }
-
- bool fromString(const char *address);
- bool fromString(const String &address) {
- return fromString(address.c_str());
- }
-
-
-
- operator uint32_t () {
- return _address.dword;
- }
- bool operator==(const IPAddress& addr) {
- return _address.dword == addr._address.dword;
- }
- bool operator==(const uint8_t* addr) {
-
- return (_address.bytes[0] == addr[0]
- && _address.bytes[1] == addr[1]
- && _address.bytes[2] == addr[2]
- && _address.bytes[3] == addr[3]);
- }
-
-
- uint8_t operator[](int index) const {
- return _address.bytes[index];
- };
- uint8_t& operator[](int index) {
- return _address.bytes[index];
- };
-
-
- IPAddress& operator=(const uint8_t *address) {
-
- _address.bytes[0] = *address++;
- _address.bytes[1] = *address++;
- _address.bytes[2] = *address++;
- _address.bytes[3] = *address++;
- return *this;
- }
- IPAddress& operator=(uint32_t address) {
- _address.dword = address;
- return *this;
- }
-
- virtual size_t printTo(Print& p) const;
-
- friend class EthernetClass;
- friend class UDP;
- friend class Client;
- friend class Server;
- friend class DhcpClass;
- friend class DNSClient;
- };
-
- const IPAddress INADDR_NONE((uint32_t)0);
-
-
- #endif
|