diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a2966fd..811c3b14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,12 +31,12 @@ message(STATUS "Building PIP version ${VERSION}${VERSION_SUFFIX}") file(WRITE "src/pip_version_str.h" "// This file was generated by PIP CMake, don`t edit it!\n#define __PIP_VERSION_STR__ \"${VERSION}${VERSION_SUFFIX}\"\n") #options -option(ICU "Unicode support" ON) -option(USB "USB support" OFF) -option(STL "Building with STL containers" OFF) -option(CRYPT "Crypt support" OFF) -option(LIB "System install" ON) -option(DEBUG "Build with -g3" OFF) +option(ICU "Unicode support" 1) +option(USB "USB support" 0) +option(STL "Building with STL containers" 0) +option(CRYPT "Crypt support" 0) +option(LIB "System install" 1) +option(DEBUG "Build with -g3" 0) set(CMAKE_BUILD_TYPE "Release") set(LIBS) if (DEBUG) diff --git a/main.cpp b/main.cpp index 7cbb1ba5..03cf35ee 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include "pikbdlistener.h" #include "piconnection.h" #include "piconfig.h" +#include "piethernet.h" int main (int argc, char * argv[]) { /*PIKbdListener k; @@ -11,7 +12,6 @@ int main (int argc, char * argv[]) { k.start(); WAIT_FOR_EXIT return 0;*/ - PIConfig c("mems.conf"); - piCout << c.allTree(); + piCout << PIEthernet::resolve(argv[1]); } diff --git a/src/io/piethernet.cpp b/src/io/piethernet.cpp index 43fc5199..6e692c6a 100755 --- a/src/io/piethernet.cpp +++ b/src/io/piethernet.cpp @@ -30,24 +30,26 @@ # endif # define ip_mreqn ip_mreq # define imr_address imr_interface -#endif -#ifdef WINDOWS -# include -# include -# include -# include -# include -# define ip_mreqn ip_mreq -# define imr_address imr_interface #else -# include -# include -# include -# include -# include -# include -# ifndef ANDROID -# include +# ifdef WINDOWS +# include +# include +# include +# include +# include +# define ip_mreqn ip_mreq +# define imr_address imr_interface +# else +# include +# include +# include +# include +# include +# include +# include +# ifndef ANDROID +# include +# endif # endif #endif #include @@ -1008,7 +1010,32 @@ PIStringList PIEthernet::allAddresses() { piForeachC (PIEthernet::Interface & i, il) al << i.address; return al.removeStrings("0.0.0.0"); + //#endif +} + + +PIString PIEthernet::resolve(const PIString & host) { + PIString ip(host), port; + int i = host.find(':'); + if (i >= 0) { + ip = host.left(i); + port = host.right(host.length() - i - 1); + } + PIString ret = PIStringAscii("0.0.0.0"); + if (!port.isEmpty()) ret += PIStringAscii(":") + port; +//#ifdef WINDOWS + hostent * he = gethostbyname(ip.dataAscii()); + if (!he) + return ret; + struct in_addr addr; + if (he->h_addr_list[0]) { + addr.s_addr = *((uint*)(he->h_addr_list[0])); + ret = inet_ntoa(addr); + if (!port.isEmpty()) ret += PIStringAscii(":") + port; + } +//#else //#endif + return ret; } diff --git a/src/io/piethernet.h b/src/io/piethernet.h index cbadf942..79bd2762 100755 --- a/src/io/piethernet.h +++ b/src/io/piethernet.h @@ -329,6 +329,9 @@ public: //! Returns all system network IP addresses static PIStringList allAddresses(); + //! Resolve hostname "host" and return it IPv4 address or "0.0.0.0" on error + static PIString resolve(const PIString & host); + static void parseAddress(const PIString & ipp, PIString * ip, int * port); static PIString macFromBytes(const PIByteArray & mac); static PIByteArray macToBytes(const PIString & mac);