many changes

This commit is contained in:
kazu
2018-09-22 15:44:26 +02:00
parent 528a00b0e9
commit 90e9fee101
11 changed files with 1581 additions and 476 deletions

121
net/IP.h
View File

@@ -1,46 +1,105 @@
#ifndef IP_H
#define IP_H
#include "../Platforms.h"
#define Port uint16_t
struct IP {
#if ESP8266
//uint32_t val;
ip_addr addr;
struct IP4 {
/** empty ctor */
explicit IP() {
addr.addr = 0;
}
//uint32_t val;
ip_addr_t addr;
/** ctor with IP-string */
explicit IP(const char* ipStr) {
set(ipStr);
}
/** empty ctor */
explicit IP() {
addr.addr = 0;
}
/** ctor with ip_addr_t */
explicit IP(ip_addr addr) : addr(addr) {
;
}
/** ctor with IP-string */
explicit IP(const char* ipStr) {
set(ipStr);
}
/** set the IP by string: x.x.x.x */
void set(const char* ipStr) {
addr.addr = ipaddr_addr(ipStr);
}
/** ctor with ip_addr_t */
explicit IP(ip_addr addr) : addr(addr) {
;
}
/** convert to ip_addr/ip_addr_t */
const ip_addr* getPtr() const {
return &addr;
}
/** set the IP by string: x.x.x.x */
void set(const char* ipStr) {
addr.addr = ipaddr_addr(ipStr);
}
/** convert to string */
const char* toString() const {
//static char str[16];
//ipaddr_aton(str, (ip_addr*)&addr);
//return str;
return ipaddr_ntoa(&addr);
}
/** 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