Files
ESP8266lib/net/IP.h
kazu 5cb02880b3 many updates..
new sensors.. display.. led.. drawing.. stuff..
2019-01-17 23:12:01 +01:00

106 lines
1.7 KiB
C

#ifndef IP_H
#define IP_H
#include "../Platforms.h"
#define Port uint16_t
#if ESP8266
struct IP4 {
//uint32_t val;
ip_addr_t addr;
/** empty ctor */
explicit IP4() {
addr.addr = 0;
}
/** ctor with IP-string */
explicit IP4(const char* ipStr) {
set(ipStr);
}
/** ctor with ip_addr_t */
explicit IP4(ip_addr addr) : addr(addr) {
;
}
/** set the IP by string: x.x.x.x */
void set(const char* ipStr) {
addr.addr = ipaddr_addr(ipStr);
}
/** convert to ip_addr/ip_addr_t */
const ip_addr* getPtr() const {
return &addr;
}
/** convert to string */
const char* toString() const {
//static char str[16];
//ipaddr_aton(str, (ip_addr*)&addr);
//return str;
return ipaddr_ntoa(&addr);
}
};
#elif ESP32
#include <lwip/ip.h>
struct IP4 {
ip_addr_t addr;
/** empty ctor */
explicit IP4() {
addr.type = IPADDR_TYPE_V4;
addr.u_addr.ip4.addr = 0;
}
/** ctor with IP-string */
explicit IP4(const char* ipStr) {
addr.type = IPADDR_TYPE_V4;
set(ipStr);
}
/** ctor with ip4_addr */
explicit IP4(ip4_addr _addr) {
addr.type = IPADDR_TYPE_V4;
addr.u_addr.ip4 = _addr;
}
/** ctor with ip_addr_t */
explicit IP4(ip_addr_t _addr) {
addr = _addr;
}
/** set the IP by string: x.x.x.x */
void set(const char* ipStr) {
//addr.u_addr.ip4 = ip4addr_aton(ipStr);
ip4addr_aton(ipStr, &addr.u_addr.ip4);
}
/** convert to ip_addr/ip_addr_t */
const ip_addr_t* getPtr() const {
return &addr;
}
/** convert to string */
const char* toString() const {
//static char str[16];
//ipaddr_aton(str, (ip_addr*)&addr);
//return str;
return ipaddr_ntoa(&addr);
}
};
#endif
#endif // IP_H