47 lines
698 B
C
47 lines
698 B
C
#ifndef IP_H
|
|
#define IP_H
|
|
|
|
#define Port uint16_t
|
|
|
|
struct IP {
|
|
|
|
//uint32_t val;
|
|
ip_addr addr;
|
|
|
|
/** empty ctor */
|
|
explicit IP() {
|
|
addr.addr = 0;
|
|
}
|
|
|
|
/** ctor with IP-string */
|
|
explicit IP(const char* ipStr) {
|
|
set(ipStr);
|
|
}
|
|
|
|
/** ctor with ip_addr_t */
|
|
explicit IP(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);
|
|
}
|
|
|
|
};
|
|
|
|
#endif // IP_H
|