Project "Tuxbox-GIT: apps":

The branch, master has been updated
       via  f059bbcc7cab8c6e3395a7618455342dcbb47194 (commit)
      from  1b648fcacc68c6a569bb8cb17df924a9375e8f75 (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 f059bbcc7cab8c6e3395a7618455342dcbb47194
Author: m4r...@gmx.de <m4r...@gmx.de>
Date:   Mon May 25 23:34:59 2015 +0200

    convert char[...] configuration values to std::string (libnet)
    
    based on martii's code with some changes for dbox
    
    Signed-off-by: GetAway <get-a...@t-online.de>

diff --git a/misc/libs/libnet/Makefile.am b/misc/libs/libnet/Makefile.am
index b084bd8..5f5bfcb 100644
--- a/misc/libs/libnet/Makefile.am
+++ b/misc/libs/libnet/Makefile.am
@@ -1,6 +1,6 @@
 lib_LTLIBRARIES = libtuxbox-net.la
 
-libtuxbox_net_la_SOURCES = libnet.c network_interfaces.cpp
+libtuxbox_net_la_SOURCES = libnet.cpp network_interfaces.cpp
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = tuxbox-net.pc
diff --git a/misc/libs/libnet/libnet.c b/misc/libs/libnet/libnet.cpp
similarity index 55%
rename from misc/libs/libnet/libnet.c
rename to misc/libs/libnet/libnet.cpp
index c7e88b7..5af7eb7 100644
--- a/misc/libs/libnet/libnet.c
+++ b/misc/libs/libnet/libnet.cpp
@@ -9,6 +9,10 @@
 #include <netdb.h>
 #include <linux/route.h>
 
+#include "libnet.h"
+
+#if 0
+//never used
 static void    scanip( char *str, unsigned char *to )
 {
        int             val;
@@ -33,7 +37,7 @@ static        void    scanip( char *str, unsigned char *to )
                sp++;
        }
 }
-       
+
 int    netSetIP( char *dev, char *ip, char *mask, char *brdcast )
 {
        int                                     fd;
@@ -53,24 +57,24 @@ int netSetIP( char *dev, char *ip, char *mask, char 
*brdcast )
        scanip( brdcast, adr_brdcast );
 
        /* init structures */
-       memset(&req, 0, sizeof(req));
+       memset(&req,0,sizeof(req));
        strcpy(req.ifr_name,dev);
 
-       memset(&addr, 0, sizeof(addr));
+       memset(&addr,0,sizeof(addr));
        addr.sin_family = AF_INET;
 
        addr.sin_addr.s_addr = *((unsigned long *) adr_ip);
-       memcpy(&req.ifr_addr,&addr,sizeof(addr));
+       memmove(&req.ifr_addr,&addr,sizeof(addr));
        if( ioctl(fd,SIOCSIFADDR,&req) < 0 )
                goto abbruch;
 
        addr.sin_addr.s_addr = *((unsigned long *) adr_mask);
-       memcpy(&req.ifr_addr,&addr,sizeof(addr));
+       memmove(&req.ifr_addr,&addr,sizeof(addr));
        if( ioctl(fd,SIOCSIFNETMASK,&req) < 0 )
                goto abbruch;
 
        addr.sin_addr.s_addr = *((unsigned long *) adr_brdcast);
-       memcpy(&req.ifr_addr,&addr,sizeof(addr));
+       memmove(&req.ifr_addr,&addr,sizeof(addr));
        if( ioctl(fd,SIOCSIFBRDADDR,&req) < 0 )
                goto abbruch;
 
@@ -80,48 +84,53 @@ abbruch:
 
        return rc;
 }
-
-void   netGetIP( char *dev, char *ip, char *mask, char *brdcast )
+#endif
+void   netGetIP(std::string &dev, std::string &ip, std::string &mask, 
std::string &brdcast)
 {
        int                                     fd;
        struct ifreq            req;
        struct sockaddr_in      *saddr;
        unsigned char           *addr;
 
-       *ip=0;
-       *mask=0;
-       *brdcast=0;
+       ip = "";
+       mask = "";
+       brdcast = "";
 
        fd=socket(AF_INET,SOCK_DGRAM,0);
        if ( !fd )
                return;
 
 
-       memset(&req, 0, sizeof(req));
-       strcpy(req.ifr_name,dev);
+       memset(&req,0,sizeof(req));
+       strncpy(req.ifr_name, dev.c_str(), sizeof(req.ifr_name));
        saddr = (struct sockaddr_in *) &req.ifr_addr;
        addr= (unsigned char*) &saddr->sin_addr.s_addr;
 
+       char tmp[80];
+
        if( ioctl(fd,SIOCGIFADDR,&req) == 0 )
-               sprintf(ip,"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]);
+               snprintf(tmp, 
sizeof(tmp),"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]);
+       ip = std::string(tmp);
 
        if( ioctl(fd,SIOCGIFNETMASK,&req) == 0 )
-               sprintf(mask,"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]);
+               snprintf(tmp, 
sizeof(tmp),"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]);
+       mask = std::string(tmp);
 
        if( ioctl(fd,SIOCGIFBRDADDR,&req) == 0 )
-               sprintf(brdcast,"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]);
+               snprintf(tmp, 
sizeof(tmp),"%d.%d.%d.%d",addr[0],addr[1],addr[2],addr[3]);
+       brdcast = std::string(tmp);
 
        close(fd);
-       return;
 }
-
+#if 0
+//never used
 void   netSetDefaultRoute( char *gw )
 {
        struct rtentry          re;
        struct sockaddr_in      *in_addr;
        unsigned char           *addr;
        int                                     fd;
-       unsigned char           adr_gw[4];
+       unsigned char           adr_gw[4] = {0};
 
        scanip( gw, adr_gw );
 
@@ -142,44 +151,48 @@ void      netSetDefaultRoute( char *gw )
                return;
 
        re.rt_flags = RTF_GATEWAY | RTF_UP;
-       memcpy(addr,adr_gw,4);
+       memmove(addr,adr_gw,4);
 
        ioctl(fd,SIOCADDRT,&re);
 
        close(fd);
        return;
 }
-
-void netGetDefaultRoute( char *ip )
+#endif
+void netGetDefaultRoute( std::string &ip )
 {
        FILE *fp;
        char interface[9];
-       unsigned char destination[4];
-       unsigned char gateway[4];
+       uint32_t destination;
+       uint32_t gw;
+       uint8_t gateway[4];
        char zeile[256];
 
-       *ip = 0 ;
+       ip = "";
        fp = fopen("/proc/net/route","r");
        if (fp == NULL)
                return;
-       fgets(zeile,sizeof(zeile),fp);
+       fgets(zeile,sizeof(zeile),fp); /* skip header */
        while(fgets(zeile,sizeof(zeile),fp))
        {
-               sscanf(zeile,"%8s %x %x",interface,(unsigned *) 
destination,(unsigned *) gateway);
-               if (*(unsigned *)destination == 0)
-               {
-                       
sprintf(ip,"%d.%d.%d.%d",gateway[0],gateway[1],gateway[2],gateway[3]);
-                       break;
-               }
+               destination = 1; /* in case sscanf fails */
+               sscanf(zeile,"%8s %x %x", interface, &destination, &gw);
+               if (destination)
+                       continue;
+               /* big/little endian kernels have reversed entries, so this is 
correct */
+               memcpy(gateway, &gw, 4);
+               char tmp[80];
+               snprintf(tmp, sizeof(tmp), "%d.%d.%d.%d", gateway[0], 
gateway[1], gateway[2], gateway[3]);
+               ip = std::string(tmp);
+               break;
        }
        fclose(fp);
 }
 
+#if 0
 static char    dombuf[256];
-static char    hostbuf[256];
 static char    domis=0;
-static char    hostis=0;
-
+//never used
 char   *netGetDomainname( void )
 {
        if (!domis)
@@ -194,50 +207,55 @@ void      netSetDomainname( char *dom )
        domis=1;
        setdomainname(dombuf,strlen(dombuf)+1);
 }
-
-char   *netGetHostname( void )
+#endif
+void netGetHostname( std::string &host )
 {
-       if (!hostis)
-               gethostname( hostbuf, 256 );
-       hostis=1;
-       return hostbuf;
+       host = "";
+       char hostbuf[256];
+       if (!gethostname(hostbuf, sizeof(hostbuf)))
+               host = std::string(hostbuf);
 }
 
-void   netSetHostname( char *host )
+void   netSetHostname( std::string &host )
 {
-       strcpy(hostbuf,host);
-       hostis=1;
-       sethostname(hostbuf,strlen(hostbuf)+1);
+       FILE * fp;
+
+       sethostname(host.c_str(), host.length());
+       fp = fopen("/etc/hostname", "w");
+       if(fp != NULL) {
+               fprintf(fp, "%s\n", host.c_str());
+               fclose(fp);
+       }
 }
 
-void   netSetNameserver(const char * const ip)
+void   netSetNameserver(std::string &ip)
 {
        FILE    *fp;
-       char    *dom;
 
        fp = fopen("/etc/resolv.conf","w");
        if (!fp)
                return;
 
 #if 0
+       char    *dom;
        dom=netGetDomainname();
        if (dom && strlen(dom)>2)
                fprintf(fp,"search %s\n",dom);
 #endif
        fprintf(fp, "# generated by neutrino\n");
-       if ((ip != NULL) && (strlen(ip) > 0))
-               fprintf(fp,"nameserver %s\n",ip);
+       if (!ip.empty())
+               fprintf(fp,"nameserver %s\n",ip.c_str());
        fclose(fp);
 }
 
-void   netGetNameserver( char *ip )
+void   netGetNameserver( std::string &ip )
 {
        FILE *fp;
        char zeile[256];
-       char *index;
+       char *indexLocal;
        unsigned zaehler;
 
-       *ip = 0;
+       ip = "";
        fp = fopen("/etc/resolv.conf","r");
        if (!fp)
                return;
@@ -246,15 +264,36 @@ void      netGetNameserver( char *ip )
        {
                if (!strncasecmp(zeile,"nameserver",10))
                {
-                       index = zeile + 10;
-                       while ( (*index == ' ') || (*index == '\t') )
-                               index++;
+                       char tmp[20];
+                       indexLocal = zeile + 10;
+                       while ( (*indexLocal == ' ') || (*indexLocal == '\t') )
+                               indexLocal++;
                        zaehler = 0;
-                       while ( (zaehler < 15) && ( ((*index >= '0') && (*index 
<= '9')) || (*index == '.')))
-                               ip[zaehler++] = *(index++);
-                       ip[zaehler] = 0;
+                       while ( (zaehler < 15) && ( ((*indexLocal >= '0') && 
(*indexLocal <= '9')) || (*indexLocal == '.')))
+                               tmp[zaehler++] = *(indexLocal++);
+                       tmp[zaehler] = 0;
+                       ip = std::string(tmp);
                        break;
                }
        }
        fclose(fp);
 }
+
+void netGetMacAddr(std::string &ifname, unsigned char *mac)
+{
+       int fd;
+       struct ifreq ifr;
+
+       memset(mac, 0, 6);
+       fd = socket(AF_INET, SOCK_DGRAM, 0);
+       if(fd < 0)
+               return;
+
+       ifr.ifr_addr.sa_family = AF_INET;
+       strncpy(ifr.ifr_name, ifname.c_str(), sizeof(ifr.ifr_name));
+
+       if(ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
+               return;
+
+       memmove(mac, ifr.ifr_hwaddr.sa_data, 6);
+}
diff --git a/misc/libs/libnet/libnet.h b/misc/libs/libnet/libnet.h
index a1ddad9..37b1794 100644
--- a/misc/libs/libnet/libnet.h
+++ b/misc/libs/libnet/libnet.h
@@ -1,27 +1,18 @@
 #ifndef __libnet__
 #define __libnet__
 
-#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
-
-
-extern  int    netSetIP( char *dev, char *ip, char *mask, char *brdcast );
-extern  void   netGetIP( char *dev, char *ip, char *mask, char *brdcast );
-extern  void   netSetDefaultRoute( char *gw );
-extern  void   netGetDefaultRoute( char *ip );
-extern char    *netGetDomainname( void );
-extern void    netSetDomainname( char *dom );
-extern char    *netGetHostname( void );
-extern void    netSetHostname( char *host );
-extern void    netSetNameserver(const char *ip);
-extern  void   netGetNameserver( char *ip );
-
-
-#ifdef __cplusplus
-}
-#endif
+#include <string>
 
+int    netSetIP(std::string &dev, std::string &ip, std::string &mask, 
std::string &brdcast );
+void   netGetIP(std::string &dev, std::string &ip, std::string &mask, 
std::string &brdcast );
+void   netSetDefaultRoute( std::string &gw );
+void   netGetDefaultRoute( std::string &ip );
+void   netGetDomainname( std::string &dom );
+void   netSetDomainname( std::string &dom );
+void   netGetHostname( std::string &host );
+void   netSetHostname( std::string &host );
+void   netSetNameserver(std::string &ip);
+void   netGetNameserver( std::string &ip );
+void   netGetMacAddr(std::string & ifname, unsigned char *);
 
 #endif
diff --git a/tuxbox/neutrino/src/gui/network_setup.cpp 
b/tuxbox/neutrino/src/gui/network_setup.cpp
index f4906aa..50abdda 100644
--- a/tuxbox/neutrino/src/gui/network_setup.cpp
+++ b/tuxbox/neutrino/src/gui/network_setup.cpp
@@ -455,11 +455,9 @@ void CNetworkSetup::restoreNetworkSettings(bool 
show_message)
 
 void CNetworkSetup::testNetworkSettings()
 {
-       char our_ip[16];
-       char our_mask[16];
-       char our_broadcast[16];
-       char our_gateway[16];
-       char our_nameserver[16];
+       std::string ifname = "eth0";
+       std::string our_ip, our_mask, our_broadcast, our_gateway, 
our_nameserver;
+
        std::string text, ethID, testsite;
        //set default testdomain and wiki-IP
        std::string defaultsite = "www.google.de", wiki_IP = "91.224.67.93";
@@ -479,36 +477,36 @@ void CNetworkSetup::testNetworkSettings()
                testsite = defaultsite; 
 
        if (networkConfig->inet_static) {
-               strcpy(our_ip, networkConfig->address.c_str());
-               strcpy(our_mask, networkConfig->netmask.c_str());
-               strcpy(our_broadcast, networkConfig->broadcast.c_str());
-               strcpy(our_gateway, networkConfig->gateway.c_str());
-               strcpy(our_nameserver, networkConfig->nameserver.c_str());
+               our_ip = networkConfig->address;
+               our_mask = networkConfig->netmask;
+               our_broadcast = networkConfig->broadcast;
+               our_gateway = networkConfig->gateway;
+               our_nameserver = networkConfig->nameserver;
        }
        else {
-               netGetIP("eth0", our_ip, our_mask, our_broadcast);
+               netGetIP(ifname, our_ip, our_mask, our_broadcast);
                netGetDefaultRoute(our_gateway);
                netGetNameserver(our_nameserver);
        }
        
-       printf("testNw IP: %s\n", our_ip);
+       printf("testNw IP: %s\n", our_ip.c_str());
        printf("testNw MAC-address: %s\n", ethID.c_str());
-       printf("testNw Netmask: %s\n", our_mask);
-       printf("testNw Broadcast: %s\n", our_broadcast);
-       printf("testNw Gateway: %s\n", our_gateway);
-       printf("testNw Nameserver: %s\n", our_nameserver);
+       printf("testNw Netmask: %s\n", our_mask.c_str());
+       printf("testNw Broadcast: %s\n", our_broadcast.c_str());
+       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) + '\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) + 
'\n'
+            + "    " + our_gateway + ": " + ' ' + 
mypinghost(our_gateway.c_str()) + '\n'
             + g_Locale->getText(LOCALE_NETWORKMENU_NAMESERVER) + ":\n"
-            + "    " + our_nameserver + ": " + ' ' + 
mypinghost(our_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)) text += (std::string)
+       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';
@@ -518,15 +516,11 @@ void CNetworkSetup::testNetworkSettings()
 
 void CNetworkSetup::showCurrentNetworkSettings()
 {
-       char ip[16];
-       char mask[16];
-       char broadcast[16];
-       char router[16];
-       char nameserver[16];
-       std::string text;
-       
-       netGetIP("eth0", ip, mask, broadcast);
-       if (ip[0] == 0) {
+       std::string ifname = "eth0";
+       std::string ip, mask, broadcast, router, nameserver, text;
+       netGetIP(ifname, ip, mask, broadcast);
+
+       if (ip.empty()) {
                text = g_Locale->getText(LOCALE_NETWORKMENU_INACTIVE);
        }
        else {
diff --git a/tuxbox/neutrino/src/system/Makefile.am 
b/tuxbox/neutrino/src/system/Makefile.am
index 6949593..6254b90 100644
--- a/tuxbox/neutrino/src/system/Makefile.am
+++ b/tuxbox/neutrino/src/system/Makefile.am
@@ -15,10 +15,15 @@ endif
 noinst_LIBRARIES = libneutrino_system.a
 
 libneutrino_system_a_SOURCES = \
-       localize.cpp setting_helpers.cpp debug.cpp \
-       ping.c flashtool.cpp \
-       settings.cpp lastchannel.cpp \
-       configure_network.cpp helper.cpp
+       localize.cpp \
+       setting_helpers.cpp \
+       debug.cpp \
+       ping.c \
+       flashtool.cpp \
+       settings.cpp \
+       lastchannel.cpp \
+       configure_network.cpp \
+       helper.cpp
 
 if !DISABLE_INTERNET_UPDATE
 libneutrino_system_a_SOURCES += httptool.cpp
diff --git a/tuxbox/neutrino/src/system/configure_network.cpp 
b/tuxbox/neutrino/src/system/configure_network.cpp
index 88314a8..fb8425d 100644
--- a/tuxbox/neutrino/src/system/configure_network.cpp
+++ b/tuxbox/neutrino/src/system/configure_network.cpp
@@ -27,9 +27,7 @@
 
 CNetworkConfig::CNetworkConfig(void)
 {
-       char our_nameserver[16];
-       netGetNameserver(our_nameserver);
-       nameserver = our_nameserver;
+       netGetNameserver(nameserver);
        inet_static = getInetAttributes("eth0", automatic_start, address, 
netmask, broadcast, gateway);
        copy_to_orig();
 }
@@ -93,7 +91,7 @@ void CNetworkConfig::commitConfig(void)
        if (nameserver != orig_nameserver)
        {
                orig_nameserver = nameserver;
-               netSetNameserver(nameserver.c_str());
+               netSetNameserver(nameserver);
        }
 }
 
diff --git a/tuxbox/neutrino/src/system/setting_helpers.cpp 
b/tuxbox/neutrino/src/system/setting_helpers.cpp
index 55a78af..538356c 100644
--- a/tuxbox/neutrino/src/system/setting_helpers.cpp
+++ b/tuxbox/neutrino/src/system/setting_helpers.cpp
@@ -241,22 +241,18 @@ std::string getPidof(const std::string& process_name)
 //returns interface
 std::string getInterface()
 {
-       char ret[19];
-       char ip[3][16];
-       char our_ip[3][16];
+       std::string ifname = "eth0";
+       std::string our_ip, our_mask, our_broadcast;
 
        CNetworkConfig  *network = CNetworkConfig::getInstance();
        
        if (network->inet_static)
        {
-               sprintf(ip[0], "%s", network->address.c_str());
-               strcpy(our_ip[0], ip[0]);
+               our_ip = network->address;
        }
        else    //Note: netGetIP returns also mask and broadcast, but not 
needed here 
-               netGetIP("eth0", our_ip[0]/*IP*/, our_ip[1]/*MASK*/, 
our_ip[2]/*BROADCAST*/);
-
-       sprintf(ret, "%s/24", our_ip[0]);
+               netGetIP(ifname, our_ip, our_mask, our_broadcast);
        
-       return ret;
+       return our_ip + "/24";
 }
 

-----------------------------------------------------------------------

Summary of changes:
 misc/libs/libnet/Makefile.am                     |    2 +-
 misc/libs/libnet/{libnet.c => libnet.cpp}        |  155 ++++++++++++++--------
 misc/libs/libnet/libnet.h                        |   33 ++---
 tuxbox/neutrino/src/gui/network_setup.cpp        |   52 ++++----
 tuxbox/neutrino/src/system/Makefile.am           |   13 ++-
 tuxbox/neutrino/src/system/configure_network.cpp |    6 +-
 tuxbox/neutrino/src/system/setting_helpers.cpp   |   14 +--
 7 files changed, 149 insertions(+), 126 deletions(-)
 rename misc/libs/libnet/{libnet.c => libnet.cpp} (55%)


-- 
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

Reply via email to