147 lines
2.3 KiB
C
147 lines
2.3 KiB
C
#ifndef IP_H
|
|
#define IP_H
|
|
|
|
#include "../Platforms.h"
|
|
|
|
#define Port uint16_t
|
|
|
|
|
|
#if OLD_IS_ESP8266 // RAW
|
|
|
|
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 IS_ESP8266 // freeRTOS
|
|
|
|
#include <lwip/ip.h>
|
|
|
|
struct IP4 {
|
|
|
|
ip4_addr addr;
|
|
|
|
/** empty ctor */
|
|
explicit IP4() {
|
|
addr.addr = 0;
|
|
}
|
|
|
|
/** ctor with IP-string */
|
|
explicit IP4(const char* ipStr) {
|
|
set(ipStr);
|
|
}
|
|
|
|
/** ctor with ip4_addr */
|
|
explicit IP4(ip4_addr _addr) {
|
|
addr =_addr;
|
|
}
|
|
|
|
/** set the IP by string: x.x.x.x */
|
|
void set(const char* ipStr) {
|
|
ip4addr_aton(ipStr, &addr);
|
|
}
|
|
|
|
/** convert to ip_addr/ip_addr_t */
|
|
const ip_addr_t* getPtr() const {
|
|
return &addr;
|
|
}
|
|
|
|
/** convert to string */
|
|
const char* toString() const {
|
|
return ipaddr_ntoa(&addr);
|
|
}
|
|
|
|
};
|
|
|
|
#elif IS_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
|