mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Added Printable interface class to allow printing of classes such as IPAddress
This commit is contained in:
@ -42,3 +42,13 @@ bool IPAddress::operator==(const uint8_t* addr)
|
||||
return memcmp(addr, _address, sizeof(_address)) == 0;
|
||||
}
|
||||
|
||||
void IPAddress::printTo(Print& p) const
|
||||
{
|
||||
for (int i =0; i < 3; i++)
|
||||
{
|
||||
p.print(_address[i], DEC);
|
||||
p.print('.');
|
||||
}
|
||||
p.print(_address[3], DEC);
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,11 @@
|
||||
#ifndef IPAddress_h
|
||||
#define IPAddress_h
|
||||
|
||||
#include <Printable.h>
|
||||
|
||||
// A class to make it easier to handle and pass around IP addresses
|
||||
|
||||
class IPAddress {
|
||||
class IPAddress : public Printable {
|
||||
private:
|
||||
uint8_t _address[4]; // IPv4 address
|
||||
// Access the raw byte array containing the address. Because this returns a pointer
|
||||
@ -58,6 +60,8 @@ public:
|
||||
IPAddress& operator=(const uint8_t *address);
|
||||
IPAddress& operator=(uint32_t address);
|
||||
|
||||
virtual void printTo(Print& p) const;
|
||||
|
||||
friend class EthernetClass;
|
||||
friend class UDP;
|
||||
friend class Client;
|
||||
|
Reference in New Issue
Block a user