PIEthernet:resolve()
git-svn-id: svn://db.shs.com.ru/pip@171 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -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")
|
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
|
#options
|
||||||
option(ICU "Unicode support" ON)
|
option(ICU "Unicode support" 1)
|
||||||
option(USB "USB support" OFF)
|
option(USB "USB support" 0)
|
||||||
option(STL "Building with STL containers" OFF)
|
option(STL "Building with STL containers" 0)
|
||||||
option(CRYPT "Crypt support" OFF)
|
option(CRYPT "Crypt support" 0)
|
||||||
option(LIB "System install" ON)
|
option(LIB "System install" 1)
|
||||||
option(DEBUG "Build with -g3" OFF)
|
option(DEBUG "Build with -g3" 0)
|
||||||
set(CMAKE_BUILD_TYPE "Release")
|
set(CMAKE_BUILD_TYPE "Release")
|
||||||
set(LIBS)
|
set(LIBS)
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
|
|||||||
4
main.cpp
4
main.cpp
@@ -1,6 +1,7 @@
|
|||||||
#include "pikbdlistener.h"
|
#include "pikbdlistener.h"
|
||||||
#include "piconnection.h"
|
#include "piconnection.h"
|
||||||
#include "piconfig.h"
|
#include "piconfig.h"
|
||||||
|
#include "piethernet.h"
|
||||||
|
|
||||||
int main (int argc, char * argv[]) {
|
int main (int argc, char * argv[]) {
|
||||||
/*PIKbdListener k;
|
/*PIKbdListener k;
|
||||||
@@ -11,7 +12,6 @@ int main (int argc, char * argv[]) {
|
|||||||
k.start();
|
k.start();
|
||||||
WAIT_FOR_EXIT
|
WAIT_FOR_EXIT
|
||||||
return 0;*/
|
return 0;*/
|
||||||
PIConfig c("mems.conf");
|
piCout << PIEthernet::resolve(argv[1]);
|
||||||
piCout << c.allTree();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
# endif
|
# endif
|
||||||
# define ip_mreqn ip_mreq
|
# define ip_mreqn ip_mreq
|
||||||
# define imr_address imr_interface
|
# define imr_address imr_interface
|
||||||
#endif
|
#else
|
||||||
# ifdef WINDOWS
|
# ifdef WINDOWS
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
@@ -46,10 +46,12 @@
|
|||||||
# include <arpa/inet.h>
|
# include <arpa/inet.h>
|
||||||
# include <sys/socket.h>
|
# include <sys/socket.h>
|
||||||
# include <net/if.h>
|
# include <net/if.h>
|
||||||
|
# include <netdb.h>
|
||||||
# ifndef ANDROID
|
# ifndef ANDROID
|
||||||
# include <ifaddrs.h>
|
# include <ifaddrs.h>
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
#endif
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -1012,6 +1014,31 @@ PIStringList PIEthernet::allAddresses() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// System wrap
|
// System wrap
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -329,6 +329,9 @@ public:
|
|||||||
//! Returns all system network IP addresses
|
//! Returns all system network IP addresses
|
||||||
static PIStringList allAddresses();
|
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 void parseAddress(const PIString & ipp, PIString * ip, int * port);
|
||||||
static PIString macFromBytes(const PIByteArray & mac);
|
static PIString macFromBytes(const PIByteArray & mac);
|
||||||
static PIByteArray macToBytes(const PIString & mac);
|
static PIByteArray macToBytes(const PIString & mac);
|
||||||
|
|||||||
Reference in New Issue
Block a user