Project "Tuxbox-GIT: apps": The branch, master has been updated via b3f66515501cbd1bad8d572ca4b2f58f630a3b18 (commit) from f059bbcc7cab8c6e3395a7618455342dcbb47194 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit b3f66515501cbd1bad8d572ca4b2f58f630a3b18 Author: m4r...@gmx.de <m4r...@gmx.de> Date: Tue May 26 12:09:16 2015 +0200 convert char[...] configuration values to std::string (ping) based on martii's code with some changes for dbox Signed-off-by: GetAway <get-a...@t-online.de> diff --git a/tuxbox/neutrino/src/gui/moviebrowser.cpp b/tuxbox/neutrino/src/gui/moviebrowser.cpp index 5132b3f..d99b5ea 100644 --- a/tuxbox/neutrino/src/gui/moviebrowser.cpp +++ b/tuxbox/neutrino/src/gui/moviebrowser.cpp @@ -79,7 +79,7 @@ #include <sys/mount.h> #include <unistd.h> //#include <system/ping.h> -extern "C" int pingthost ( const char *hostname, int t ); +extern int pingthost (const std::string &hostname, int t ); #define my_scandir scandir64 #define my_alphasort alphasort64 diff --git a/tuxbox/neutrino/src/gui/network_setup.cpp b/tuxbox/neutrino/src/gui/network_setup.cpp index 50abdda..2bc8054 100644 --- a/tuxbox/neutrino/src/gui/network_setup.cpp +++ b/tuxbox/neutrino/src/gui/network_setup.cpp @@ -76,7 +76,7 @@ #include <system/debug.h> -extern "C" int pinghost( const char *hostname ); +extern int pinghost (const std::string &hostname, std::string *ip = NULL); CNetworkSetup::CNetworkSetup() { @@ -331,7 +331,7 @@ bool CNetworkSetup::checkForIP() return ret; } -const char * CNetworkSetup::mypinghost(const char * const host) +const char * CNetworkSetup::mypinghost(std::string &host) { int retvalue = pinghost(host); switch (retvalue) @@ -458,9 +458,10 @@ void CNetworkSetup::testNetworkSettings() std::string ifname = "eth0"; std::string our_ip, our_mask, our_broadcast, our_gateway, our_nameserver; - std::string text, ethID, testsite; + std::string text, ethID, testsite, offset = " "; + //set default testdomain and wiki-IP - std::string defaultsite = "www.google.de", wiki_IP = "91.224.67.93"; + std::string defaultsite = "www.google.de", wiki_IP = "91.224.67.93", wiki_URL = "wiki.tuxbox.org"; //set physical adress static CNetAdapter netadapter; @@ -496,20 +497,32 @@ void CNetworkSetup::testNetworkSettings() printf("testNw Gateway: %s\n", our_gateway.c_str()); printf("testNw Nameserver: %s\n", our_nameserver.c_str()); printf("testNw Testsite %s\n", testsite.c_str()); - - text = (std::string)"dbox:\n" - + " " + our_ip + ": " + mypinghost(our_ip.c_str()) + '\n' - + " " + "eth-ID: " + ethID + '\n' - + g_Locale->getText(LOCALE_NETWORKMENU_GATEWAY) + ":\n" - + " " + our_gateway + ": " + ' ' + mypinghost(our_gateway.c_str()) + '\n' - + g_Locale->getText(LOCALE_NETWORKMENU_NAMESERVER) + ":\n" - + " " + our_nameserver + ": " + ' ' + mypinghost(our_nameserver.c_str()) + '\n' - + "wiki.tuxbox.org:\n" - + " via IP (" + wiki_IP + "): " + mypinghost(wiki_IP.c_str()) + '\n'; - if (1 == pinghost(our_nameserver.c_str())) text += (std::string) - " via DNS: " + mypinghost("wiki.tuxbox.org") + '\n' - + testsite + ":\n" - + " via DNS: " + mypinghost(testsite.c_str()) + '\n'; + + if (our_ip.empty()) + { + text = g_Locale->getText(LOCALE_NETWORKMENU_INACTIVE); + } + else + { + // Box + text = "dbox (" + ethID + "):\n"; + text += offset + our_ip + ": " + mypinghost(our_ip) + "\n"; + // Gateway + text += (std::string)g_Locale->getText(LOCALE_NETWORKMENU_GATEWAY) + " (Router):\n"; + text += offset + our_gateway + ": " + " " + mypinghost(our_gateway) + "\n"; + // Nameserver + text += (std::string)g_Locale->getText(LOCALE_NETWORKMENU_NAMESERVER) + ":\n"; + text += offset + our_nameserver + ": " + " " + mypinghost(our_nameserver) + "\n"; + // Wiki + text += wiki_URL + ":\n"; + text += offset + "via IP (" + wiki_IP + "): " + mypinghost(wiki_IP) + "\n"; + if (pinghost(our_nameserver) == 1) + { + text += offset + "via DNS: " + mypinghost(wiki_URL) + "\n"; + text += testsite + ":\n"; + text += offset + "via DNS: " + mypinghost(testsite) + "\n"; + } + } ShowMsgUTF(LOCALE_NETWORKMENU_TEST, text, CMessageBox::mbrBack, CMessageBox::mbBack); // UTF-8 } diff --git a/tuxbox/neutrino/src/gui/network_setup.h b/tuxbox/neutrino/src/gui/network_setup.h index 9137518..9bcfe35 100644 --- a/tuxbox/neutrino/src/gui/network_setup.h +++ b/tuxbox/neutrino/src/gui/network_setup.h @@ -69,7 +69,7 @@ class CNetworkSetup : public CMenuTarget, CChangeObserver bool checkForIP(); bool settingsChanged(); - const char * mypinghost(const char * const host); + const char * mypinghost(std::string &host); void setBroadcast(void); public: diff --git a/tuxbox/neutrino/src/gui/widget/dirchooser.cpp b/tuxbox/neutrino/src/gui/widget/dirchooser.cpp index 683cac1..c72ebc8 100755 --- a/tuxbox/neutrino/src/gui/widget/dirchooser.cpp +++ b/tuxbox/neutrino/src/gui/widget/dirchooser.cpp @@ -39,7 +39,8 @@ #include <system/fsmounter.h> #endif //#include <system/ping.h> -extern "C" int pingthost ( const char *hostname, int t ); +extern int pingthost (const std::string &hostname, int t ); + #include <gui/filebrowser.h> #include <sys/vfs.h> // for statfs diff --git a/tuxbox/neutrino/src/system/Makefile.am b/tuxbox/neutrino/src/system/Makefile.am index 6254b90..f3bc561 100644 --- a/tuxbox/neutrino/src/system/Makefile.am +++ b/tuxbox/neutrino/src/system/Makefile.am @@ -18,7 +18,7 @@ libneutrino_system_a_SOURCES = \ localize.cpp \ setting_helpers.cpp \ debug.cpp \ - ping.c \ + ping.cpp \ flashtool.cpp \ settings.cpp \ lastchannel.cpp \ diff --git a/tuxbox/neutrino/src/system/ping.c b/tuxbox/neutrino/src/system/ping.cpp similarity index 80% rename from tuxbox/neutrino/src/system/ping.c rename to tuxbox/neutrino/src/system/ping.cpp index 8eeb242..597b42e 100644 --- a/tuxbox/neutrino/src/system/ping.c +++ b/tuxbox/neutrino/src/system/ping.cpp @@ -1,5 +1,4 @@ -/* - * $Id: ping.c,v 1.8 2007/01/24 02:19:10 guenther Exp $ +/** * PING module * * Copyright (C) 2001 Jeffrey Fulmer <jdful...@armstrong.com> @@ -19,12 +18,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * 15 Jan 2007 Guenther Change pingthost timebase from seconds to milliseconds */ -#include <resolv.h> + #include "ping.h" + #ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 #endif /*EXIT_SUCCESS*/ @@ -39,12 +38,12 @@ #define MAXDATA (MAXPKT-HDRLEN-TIMLEN) #define DEF_TIMEOUT 5 -int ident = 0; -int timo = 2000; // time in ms -int rrt; -int sock; +static int ident = 0; +static int timo = 2; +static int rrt; +static int sock = -1; -int +static int in_checksum( u_short *buf, int len ) { register long sum = 0; @@ -65,8 +64,7 @@ in_checksum( u_short *buf, int len ) return ( answer ); -} - +} int send_ping( const char *host, struct sockaddr_in *taddr ) @@ -81,31 +79,25 @@ send_ping( const char *host, struct sockaddr_in *taddr ) len = HDRLEN + DATALEN; - // init resolver because otherwiese dns requests will be cached - res_init(); - if(( proto = getprotobyname( "icmp" )) == NULL ){ return -1; } if(( hp = gethostbyname( host )) != NULL ){ - memcpy( &taddr->sin_addr, hp->h_addr_list[0], sizeof( taddr->sin_addr )); + memmove( &taddr->sin_addr, hp->h_addr_list[0], sizeof( taddr->sin_addr )); taddr->sin_port = 0; taddr->sin_family = AF_INET; } - else { - if( inet_aton( host, &taddr->sin_addr ) == 0 ){ - return -1; - } + else if( inet_aton( host, &taddr->sin_addr ) == 0 ){ + return -1; } last = ntohl( taddr->sin_addr.s_addr ) & 0xFF; - if(( last == 0x00 ) || ( last == 0xFF )){ return -1; } - if(( sock = socket( AF_INET, SOCK_RAW, proto->p_proto )) < 0 ){ + if((sock < 0) && ( sock = socket( AF_INET, SOCK_RAW, proto->p_proto )) < 0 ){ #ifdef DEBUG perror( "sock" ); #endif/*DEBUG*/ @@ -125,6 +117,7 @@ send_ping( const char *host, struct sockaddr_in *taddr ) perror( "sock" ); #endif/*DEBUG*/ close( sock ); + sock = -1; return -2; } if( ss != len ){ @@ -132,20 +125,21 @@ send_ping( const char *host, struct sockaddr_in *taddr ) perror( "malformed packet" ); #endif/*DEBUG*/ close( sock ); + sock = -1; return -2; } return 0; } -int +static int recv_ping( struct sockaddr_in *taddr ) { int len; socklen_t from; int nf, cc; unsigned char buf[ HDRLEN + DATALEN ]; - struct icmp *icp; + //struct icmp *icp; struct sockaddr_in faddr; struct timeval to; fd_set readset, writeset; @@ -161,7 +155,7 @@ recv_ping( struct sockaddr_in *taddr ) unreachable network and we'll time out here. */ if(( nf = select( sock + 1, &readset, &writeset, NULL, &to )) < 0 ){ #ifdef DEBUG - perror( "select" ); + perror( "select" ); #endif/*DEBUG*/ exit( EXIT_FAILURE ); } @@ -177,7 +171,7 @@ recv_ping( struct sockaddr_in *taddr ) exit( EXIT_FAILURE ); } - icp = (struct icmp *)(buf + HDRLEN + DATALEN ); + //icp = (struct icmp *)(buf + HDRLEN + DATALEN ); if( faddr.sin_addr.s_addr != taddr->sin_addr.s_addr ){ return 1; } @@ -196,7 +190,7 @@ recv_ping( struct sockaddr_in *taddr ) * returns an int value for the difference * between now and starttime in milliseconds. */ -int +static int elapsed_time( struct timeval *starttime ){ struct timeval *newtime; int elapsed; @@ -215,53 +209,60 @@ elapsed_time( struct timeval *starttime ){ } free(newtime); return( elapsed ); -} +} -// time t in ms -int -myping( const char *hostname, int t ) +static int +myping(const std::string &hostname, int t, struct sockaddr_in *sa = NULL) { int err; - struct sockaddr_in sa; + struct sockaddr_in _sa; struct timeval mytime; - memset(&sa, 0, sizeof(struct sockaddr_in)); + if (!sa) + sa = &_sa; + ident = getpid() & 0xFFFF; - if( t == 0 ) timo = 2000; + if( t == 0 ) timo = 2; else timo = t; (void) gettimeofday( &mytime, (struct timezone *)NULL); - if(( err = send_ping( hostname, &sa )) < 0 ){ + if(( err = send_ping( hostname.c_str(), sa )) < 0 ){ return err; } do{ - if(( rrt = elapsed_time( &mytime )) > timo ){ + if(( rrt = elapsed_time( &mytime )) > timo * 1000 ){ close( sock ); + sock = -1; return 0; } - } while( recv_ping( &sa )); + } while( recv_ping(sa)); close( sock ); + sock = -1; return 1; } int -pinghost( const char *hostname ) +pinghost(const std::string &hostname, std::string *ip) { - return myping( hostname, 0 ); + struct sockaddr_in sa; + int res = myping( hostname, 0, &sa); + if (ip) { + char *p = inet_ntoa(sa.sin_addr); + *ip = p ? std::string(p) : ""; + } + return res; } - -// time t in ms int -pingthost( const char *hostname, int t ) +pingthost(const std::string &hostname, int t) { return myping( hostname, t ); } int -tpinghost( const char *hostname ) +tpinghost(const std::string &hostname) { int ret; @@ -271,9 +272,8 @@ tpinghost( const char *hostname ) return ret; } -// time t in ms int -tpingthost( const char *hostname, int t ) +tpingthost(const std::string &hostname, int t ) { int ret; diff --git a/tuxbox/neutrino/src/system/ping.h b/tuxbox/neutrino/src/system/ping.h index a49ce10..4e3b0d6 100644 --- a/tuxbox/neutrino/src/system/ping.h +++ b/tuxbox/neutrino/src/system/ping.h @@ -25,6 +25,7 @@ #define PING_H #include <stdio.h> +#include <string> #include "ping-config.h" @@ -74,13 +75,13 @@ # include <netinet/ip_icmp.h> #endif /* defined(__linux__) */ -int send_ping( const char *host, struct sockaddr_in *taddr ); -int recv_ping( struct sockaddr_in *taddr ); +//int send_ping( const char *host, struct sockaddr_in *taddr ); +//int recv_ping( struct sockaddr_in *taddr ); -int pinghost ( const char *hostname ); -int pingthost ( const char *hostname, int t ); -int tpinghost ( const char *hostname ); -int tpingthost( const char *hostname, int t ); +int pinghost (const std::string &hostname, std::string *ip = NULL); +int pingthost (const std::string &hostname, int t ); +int tpinghost (const std::string &hostname ); +int tpingthost(const std::string &hostname, int t ); #endif/*PING_H*/ ----------------------------------------------------------------------- Summary of changes: tuxbox/neutrino/src/gui/moviebrowser.cpp | 2 +- tuxbox/neutrino/src/gui/network_setup.cpp | 49 ++++++++----- tuxbox/neutrino/src/gui/network_setup.h | 2 +- tuxbox/neutrino/src/gui/widget/dirchooser.cpp | 3 +- tuxbox/neutrino/src/system/Makefile.am | 2 +- tuxbox/neutrino/src/system/{ping.c => ping.cpp} | 88 +++++++++++----------- tuxbox/neutrino/src/system/ping.h | 13 ++-- 7 files changed, 87 insertions(+), 72 deletions(-) rename tuxbox/neutrino/src/system/{ping.c => ping.cpp} (80%) -- Tuxbox-GIT: apps ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Tuxbox-cvs-commits mailing list Tuxbox-cvs-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tuxbox-cvs-commits