separate PIEthernet::Address to PINetworkAddress, typedef PIEthernet::Address to PINetworkAddress and mark as deprecated
PIValueTree new attributes for File and Dir
This commit is contained in:
@@ -104,112 +104,6 @@ PIString getSockAddr(sockaddr * s) {
|
||||
#endif
|
||||
|
||||
|
||||
PIEthernet::Address::Address(uint _ip, ushort _port) {
|
||||
set(_ip, _port);
|
||||
}
|
||||
|
||||
|
||||
PIEthernet::Address::Address(const PIString & ip_port) {
|
||||
set(ip_port);
|
||||
}
|
||||
|
||||
|
||||
PIEthernet::Address::Address(const PIString & _ip, ushort _port) {
|
||||
set(_ip, _port);
|
||||
}
|
||||
|
||||
|
||||
PIString PIEthernet::Address::ipString() const {
|
||||
PIString ret = PIString::fromNumber(ip_b[0]);
|
||||
ret += "." + PIString::fromNumber(ip_b[1]);
|
||||
ret += "." + PIString::fromNumber(ip_b[2]);
|
||||
ret += "." + PIString::fromNumber(ip_b[3]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIString PIEthernet::Address::toString() const {
|
||||
return ipString() + ":" + PIString::fromNumber(port_);
|
||||
}
|
||||
|
||||
|
||||
void PIEthernet::Address::setIP(uint _ip) {
|
||||
ip_ = _ip;
|
||||
}
|
||||
|
||||
|
||||
void PIEthernet::Address::setIP(const PIString & _ip) {
|
||||
initIP(_ip);
|
||||
}
|
||||
|
||||
|
||||
void PIEthernet::Address::setPort(ushort _port) {
|
||||
port_ = _port;
|
||||
}
|
||||
|
||||
|
||||
void PIEthernet::Address::set(const PIString & ip_port) {
|
||||
PIString _ip;
|
||||
int p(0);
|
||||
splitIPPort(ip_port, &_ip, &p);
|
||||
port_ = p;
|
||||
initIP(_ip);
|
||||
}
|
||||
|
||||
|
||||
void PIEthernet::Address::set(const PIString & _ip, ushort _port) {
|
||||
initIP(_ip);
|
||||
port_ = _port;
|
||||
}
|
||||
|
||||
|
||||
void PIEthernet::Address::set(uint _ip, ushort _port) {
|
||||
ip_ = _ip;
|
||||
port_ = _port;
|
||||
}
|
||||
|
||||
|
||||
void PIEthernet::Address::clear() {
|
||||
ip_ = 0;
|
||||
port_ = 0;
|
||||
}
|
||||
|
||||
|
||||
bool PIEthernet::Address::isNull() const {
|
||||
return (ip_ == 0) && (port_ == 0);
|
||||
}
|
||||
|
||||
|
||||
PIEthernet::Address PIEthernet::Address::resolve(const PIString & host_port) {
|
||||
PIString host;
|
||||
int port(0);
|
||||
splitIPPort(host_port, &host, &port);
|
||||
return resolve(host, port);
|
||||
}
|
||||
|
||||
|
||||
PIEthernet::Address PIEthernet::Address::resolve(const PIString & host, ushort port) {
|
||||
Address ret(0, port);
|
||||
hostent * he = gethostbyname(host.dataAscii());
|
||||
if (!he) return ret;
|
||||
if (he->h_addr_list[0]) ret.setIP(*((uint *)(he->h_addr_list[0])));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIEthernet::Address::splitIPPort(const PIString & ipp, PIString * _ip, int * _port) {
|
||||
// piCout << "parse" << ipp;
|
||||
int sp = ipp.findLast(":");
|
||||
if (_ip != 0) *_ip = (sp >= 0 ? ipp.left(sp) : ipp);
|
||||
if (_port != 0 && sp >= 0) *_port = ipp.right(ipp.length() - ipp.find(":") - 1).toInt();
|
||||
}
|
||||
|
||||
|
||||
void PIEthernet::Address::initIP(const PIString & _ip) {
|
||||
ip_ = inet_addr(_ip.dataAscii());
|
||||
}
|
||||
|
||||
|
||||
REGISTER_DEVICE(PIEthernet)
|
||||
|
||||
|
||||
@@ -344,8 +238,8 @@ PIString PIEthernet::applyMask(const PIString & ip, const PIString & mask) {
|
||||
}
|
||||
|
||||
|
||||
PIEthernet::Address PIEthernet::applyMask(const PIEthernet::Address & ip, const PIEthernet::Address & mask) {
|
||||
Address ret(ip);
|
||||
PINetworkAddress PIEthernet::applyMask(const PINetworkAddress & ip, const PINetworkAddress & mask) {
|
||||
PINetworkAddress ret(ip);
|
||||
ret.ip_ &= mask.ip_;
|
||||
return ret;
|
||||
}
|
||||
@@ -358,8 +252,8 @@ PIString PIEthernet::getBroadcast(const PIString & ip, const PIString & mask) {
|
||||
}
|
||||
|
||||
|
||||
PIEthernet::Address PIEthernet::getBroadcast(const PIEthernet::Address & ip, const PIEthernet::Address & mask) {
|
||||
Address ret(ip);
|
||||
PINetworkAddress PIEthernet::getBroadcast(const PINetworkAddress & ip, const PINetworkAddress & mask) {
|
||||
PINetworkAddress ret(ip);
|
||||
ret.ip_ |= ~mask.ip_;
|
||||
return ret;
|
||||
}
|
||||
@@ -630,7 +524,7 @@ bool PIEthernet::listen(bool threaded) {
|
||||
}
|
||||
|
||||
|
||||
bool PIEthernet::listen(const PIEthernet::Address & addr, bool threaded) {
|
||||
bool PIEthernet::listen(const PINetworkAddress & addr, bool threaded) {
|
||||
setReadAddress(addr);
|
||||
return listen(threaded);
|
||||
}
|
||||
@@ -645,16 +539,16 @@ bool PIEthernet::send(const void * data, int size, bool threaded) {
|
||||
}
|
||||
|
||||
|
||||
bool PIEthernet::send(const PIEthernet::Address & addr, const void * data, int size, bool threaded) {
|
||||
bool PIEthernet::send(const PINetworkAddress & addr, const void * data, int size, bool threaded) {
|
||||
addr_s = addr;
|
||||
if (threaded) {
|
||||
writeThreaded(data, size);
|
||||
return true;
|
||||
}
|
||||
Address pa = addr_s;
|
||||
addr_s = addr;
|
||||
int wr = write(data, size);
|
||||
addr_s = pa;
|
||||
PINetworkAddress pa = addr_s;
|
||||
addr_s = addr;
|
||||
int wr = write(data, size);
|
||||
addr_s = pa;
|
||||
return (wr == size);
|
||||
}
|
||||
|
||||
@@ -668,15 +562,15 @@ bool PIEthernet::send(const PIByteArray & data, bool threaded) {
|
||||
}
|
||||
|
||||
|
||||
bool PIEthernet::send(const PIEthernet::Address & addr, const PIByteArray & data, bool threaded) {
|
||||
bool PIEthernet::send(const PINetworkAddress & addr, const PIByteArray & data, bool threaded) {
|
||||
if (threaded) {
|
||||
writeThreaded(data);
|
||||
return true;
|
||||
}
|
||||
Address pa = addr_s;
|
||||
addr_s = addr;
|
||||
int wr = write(data);
|
||||
addr_s = pa;
|
||||
PINetworkAddress pa = addr_s;
|
||||
addr_s = addr;
|
||||
int wr = write(data);
|
||||
addr_s = pa;
|
||||
return (wr == data.size_s());
|
||||
}
|
||||
|
||||
@@ -1302,10 +1196,10 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
|
||||
}
|
||||
|
||||
|
||||
PIEthernet::Address PIEthernet::interfaceAddress(const PIString & interface_) {
|
||||
PINetworkAddress PIEthernet::interfaceAddress(const PIString & interface_) {
|
||||
#if defined(WINDOWS) || defined(MICRO_PIP)
|
||||
piCout << "[PIEthernet] Not implemented, use \"PIEthernet::allAddresses\" or \"PIEthernet::interfaces\" instead";
|
||||
return Address();
|
||||
return PINetworkAddress();
|
||||
#else
|
||||
struct ifreq ifr;
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
@@ -1314,23 +1208,23 @@ PIEthernet::Address PIEthernet::interfaceAddress(const PIString & interface_) {
|
||||
ioctl(s, SIOCGIFADDR, &ifr);
|
||||
::close(s);
|
||||
struct sockaddr_in * sa = (struct sockaddr_in *)&ifr.ifr_addr;
|
||||
return Address(uint(sa->sin_addr.s_addr));
|
||||
return PINetworkAddress(uint(sa->sin_addr.s_addr));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PIVector<PIEthernet::Address> PIEthernet::allAddresses() {
|
||||
PIVector<PINetworkAddress> PIEthernet::allAddresses() {
|
||||
PIEthernet::InterfaceList il = interfaces();
|
||||
PIVector<Address> ret;
|
||||
PIVector<PINetworkAddress> ret;
|
||||
bool has_127 = false;
|
||||
piForeachC(PIEthernet::Interface & i, il) {
|
||||
if (i.address == "127.0.0.1") has_127 = true;
|
||||
Address a(i.address);
|
||||
PINetworkAddress a(i.address);
|
||||
if (a.ip() == 0) continue;
|
||||
ret << a;
|
||||
}
|
||||
// piCout << "[PIEthernet::allAddresses]" << al;
|
||||
if (!has_127) ret << Address("127.0.0.1");
|
||||
if (!has_127) ret << PINetworkAddress("127.0.0.1");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user