powerguru-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Powerguru-commit] [SCM] powerguru branch, master, updated. bb32c057f6ee


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. bb32c057f6ee51ac0d81d144e9313fe75c30ee08
Date: Fri, 21 Dec 2018 00:38:32 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "powerguru".

The branch, master has been updated
       via  bb32c057f6ee51ac0d81d144e9313fe75c30ee08 (commit)
       via  499e2b3fecb5c17d5106ffa0f862db6d1d6b72a0 (commit)
      from  9ea361a5c96634f8e730c33d0faa15ebf73a6ae6 (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 -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=bb32c057f6ee51ac0d81d144e9313fe75c30ee08


commit bb32c057f6ee51ac0d81d144e9313fe75c30ee08
Author: Rob Savoye <address@hidden>
Date:   Thu Dec 20 22:38:15 2018 -0700

    Update to a modern network API

diff --git a/lib/tcpip.cc b/lib/tcpip.cc
index acf749b..60a4851 100644
--- a/lib/tcpip.cc
+++ b/lib/tcpip.cc
@@ -105,9 +105,10 @@ Tcpip::createNetServer(short port, const std::string 
&protocol)
     struct in_addr  *thisaddr = 0, newaddr;
     in_addr_t       nodeaddr, netaddr;
   
+    struct addrinfo *addr = getAddrInfo("localhost", port);
     // host = hostDataGet("localhost");
     // thisaddr = reinterpret_cast<struct in_addr 
*>(_addrinfo->ai_addr->h_addr_list[0]);
-    thisaddr = &((struct sockaddr_in *)_addrinfo->ai_addr)->sin_addr;
+    //thisaddr = addr->sin_addr;
     //in_addr_t = ipaddr = thisaddr->s_addr;
     std::memset(&sock_in, 0, sizeof(sock_in));
   
@@ -329,102 +330,88 @@ Tcpip::createNetClient(const std::string &hostname, 
short port,
                        const std::string &protocol)
 {
     DEBUGLOG_REPORT_FUNCTION;
-    struct sockaddr_in sock_in;
-    int                type;
     fd_set              fdset;
     struct timeval      tval;
     int                 ret;
     int                 retries;
-  
-    memset(&sock_in, 0, sizeof(struct sockaddr_in));
-  
-    // const struct hostent *hent = hostByNameGet(thishostname);
-    // memcpy(&sock_in.sin_addr, hent->h_addr, hent->h_length);
-  
-    sock_in.sin_family = AF_INET;
-  
-#if 0
-    char                ascip[32];
-    inet_ntop(AF_INET, &sock_in.sin_addr.s_addr, ascip, INET_ADDRSTRLEN);
-    dbglogfile << "The IP address for this client socket is " << ascip << 
std::endl;
-#endif
-  
-    sock_in.sin_port = htons(port);
-  
-    // Set the protocol type
-    if (protocol == "udp") {
-        type = SOCK_DGRAM;
-    } else {
-        type = SOCK_STREAM;
-    }
-  
-    _sockfd = socket(PF_INET, type, _addrinfo->ai_protocol);
-  
-    if (_sockfd < 0) {
-        dbglogfile << "WARNING: unable to create socket: "
-                   << strerror(errno) << std::endl;
-        return ERROR;
-    }
+    std::string         portstr = std::to_string(port);
+    addrinfo            req;
+
+    // Get the address data for this host
+    struct addrinfo *addr = getAddrInfo(hostname, port);
+    if (addr) {
+        _sockfd = ::socket(addr->ai_family, addr->ai_socktype, 
_proto->p_proto);
+        if (_sockfd < 0) {
+            dbglogfile << "WARNING: unable to create socket: "
+                       << ::strerror(errno) << std::endl;
+            return ERROR;
+        }
 
-    if (connect(_sockfd, reinterpret_cast<struct sockaddr *>(&sock_in),
-                sizeof(sock_in)) < 0) {
-        retries = 1;
-        while (retries-- > 0) {
-            // We use select to wait for the read file descriptor to be
-            // active, which means there is a client waiting to connect.
-            FD_ZERO(&fdset);
-            FD_SET(_sockfd, &fdset);
-      
-            // Reset the timeout value, since select modifies it on return. To
-            // block, set the timeout to zero.
-            tval.tv_sec = 5;
-            tval.tv_usec = 0;
-      
-            ret = select(_sockfd+1, &fdset, NULL, NULL, &tval);
-      
-            // If interupted by a system call, try again
-            if (ret == -1 && errno == EINTR) {
-                dbglogfile <<
-                    "The connect() socket for fd #%d was interupted by a 
system call!"
-                           << _sockfd << std::endl;
+        dbglogfile << "Trying to connect to: " << hostname << ":" << port << 
std::endl;
+        if (::connect(_sockfd, addr->ai_addr, addr->ai_addrlen) < 0) {
+            dbglogfile << "ERROR: Couldn't connect to: " << hostname << " "
+                       << strerror(errno) << std::endl;
+            retries = 1;
+            while (retries-- > 0) {
+                // We use select to wait for the read file descriptor to be
+                // active, which means there is a client waiting to connect.
+                FD_ZERO(&fdset);
+                FD_SET(_sockfd, &fdset);
+                // Reset the timeout value, since select modifies it on 
return. To
+                // block, set the timeout to zero.
+                tval.tv_sec = 5;
+                tval.tv_usec = 0;
+                ret = ::select(_sockfd+1, &fdset, NULL, NULL, &tval);
+                // If interupted by a system call, try again
+                if (ret == -1 && errno == EINTR) {
+                    dbglogfile <<
+                        "The connect() socket for fd #%d was interupted by a 
system call!"
+                               << _sockfd << std::endl;
+                }
+                if (ret == -1) {
+                    dbglogfile <<
+                        "The connect() socket for fd #%d never was available 
for writing!"
+                               << _sockfd << std::endl;
+                    shutdown(_sockfd, SHUT_RDWR);
+                    return ERROR;
+                }
+                if (ret == 0) {
+                    dbglogfile <<
+                        "WARNING: The connect() socket for fd #%d timed out 
waiting to write!"
+                               << _sockfd << std::endl;
+                }
             }
-      
-            if (ret == -1) {
-                dbglogfile <<
-                    "The connect() socket for fd #%d never was available for 
writing!"
-                           << _sockfd << std::endl;
-                shutdown(_sockfd, SHUT_RDWR);
+            ret = ::connect(_sockfd, addr->ai_addr, addr->ai_addrlen);
+            if (ret <= 0) {
+                dbglogfile << "unable to connect to "
+                           << hostname
+                           << ", port " << port
+                           << ": " << strerror(errno) << std::endl;
+                close(_sockfd);
                 return ERROR;
             }
-      
-            if (ret == 0) {
-                dbglogfile <<
-                    "WARNING: The connect() socket for fd #%d timed out 
waiting to write!"
-                           << _sockfd << std::endl;
+            if (ret <= 0) {
+                dbglogfile << "unable to connect to "
+                           << hostname
+                           << ", port " << port
+                           << ": " << strerror(errno) << std::endl;
+                close(_sockfd);
+                return ERROR;
             }
         }
-    
-        if (connect(_sockfd,
-                    reinterpret_cast<struct sockaddr *>(&sock_in),
-                    sizeof(sock_in)) < 0) {
-            dbglogfile << "unable to connect to "
-                       << _hostname
-                       << ", port " << port
-                       << ": " << strerror(errno) << std::endl;
-            close(_sockfd);
-            return ERROR;
-        }
     }
 
+    _hostname = hostname;
+    char ascip[INET_ADDRSTRLEN];
+    std::memset(ascip, 0, INET_ADDRSTRLEN);
+    //inet_ntop(AF_INET, &_ipaddr, ascip, INET_ADDRSTRLEN);
     dbglogfile << "Client connected to service at port " << port
-               << " at IP " << inet_ntoa(sock_in.sin_addr)
+               << " at IP " << ascip
                << " using fd #" << _sockfd << std::endl;
   
     // For a client, the IO file descriptor is the same as the default one
     _sockIOfd = _sockfd;
 
-    memcpy(&_client, &sock_in, sizeof(struct sockaddr));
-
     return SUCCESS;
 }
 
@@ -687,6 +674,7 @@ Tcpip::readNet(std::vector<unsigned char> &buf)
         dbglogfile << "WARNING: Can't do anything with socket fd #"
                    << _sockfd << std::endl;
         buf.clear();
+        buf.push_back(255);
         return buf;
     }
   
@@ -843,22 +831,6 @@ Tcpip::operator = (Tcpip &tcp)
     _port = _port;
 }
 
-#if 0
-// Description: Get the hostname of this machine.
-const string
-Tcpip::netNameGet(void)
-{
-    char hostname[MAXHOSTNAMELEN];
-
-    if (_hostname.size() == 0) {
-        gethostname(hostname, MAXHOSTNAMELEN);
-        _hostname = hostname;
-    }
-    
-    return _hostname;
-}
-#endif
-
 // local Variables:
 // mode: C++
 // indent-tabs-mode: nil
diff --git a/lib/tcpip.h b/lib/tcpip.h
index 5facff9..5d80858 100644
--- a/lib/tcpip.h
+++ b/lib/tcpip.h
@@ -108,10 +108,13 @@ public:
     const std::string &remoteIP(struct in_addr addr);
     const std::string &remoteName(void);
     const std::string &remoteName(struct in_addr addr);
+    const std::string &hostname(void) { return _hostname; };
 
     Tcpip &operator = (Tcpip &tcp);
 
     void checkConsole(void) { _console = true; };
+    // Get the number of bytes in the incoming data TCP/IP packet.
+    // This is used to have more efficient memory allocation.
     int checkBytes() {
         int bytes = 0;
         ioctl(_sockfd, FIONREAD, &bytes);

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=499e2b3fecb5c17d5106ffa0f862db6d1d6b72a0


commit 499e2b3fecb5c17d5106ffa0f862db6d1d6b72a0
Author: Rob Savoye <address@hidden>
Date:   Thu Dec 20 22:31:16 2018 -0700

    Update to modern networking API.

diff --git a/lib/tcputil.cc b/lib/tcputil.cc
index 43426eb..be2610c 100644
--- a/lib/tcputil.cc
+++ b/lib/tcputil.cc
@@ -34,7 +34,7 @@
 #ifndef SIOCGIFCONF
 #include <sys/sockio.h>
 #endif
-
+#include <map>
 #include "tcputil.h"
 #include "tcpip.h"
 #include "log.h"
@@ -42,135 +42,191 @@
 
 extern LogFile dbglogfile;
 
-Tcputil::Tcputil(void)
-    : _service(0),
-      _proto(0),
-      _addrinfo(0)
+Tcputil::Tcputil(void) : Tcputil("localhost", DEFAULTPORT)
 {
-    // Get the hostname of this machine
-    char hostname[MAXHOSTNAMELEN];
-    std::memset(hostname, 0, MAXHOSTNAMELEN);
-    if (gethostname(hostname, MAXHOSTNAMELEN) == 0) {
-        _hostname = hostname;
-        dbglogfile << "The hostname for this machine is " << hostname << 
std::endl;
-    } else {
-        dbglogfile << "WARNING: Couldn't get the hostname for this machine!" 
<< std::endl;
-    }
+    DEBUGLOG_REPORT_FUNCTION;
+}
 
-    dbglogfile << "Has " << numberOfInterfaces() << " interfaces, using 
default one" << std::endl;
-
-    // Get the IP numbers for this machine
-    if (getaddrinfo(hostname, NULL, NULL, &_addrinfo) == 0) {
-        char _address[INET6_ADDRSTRLEN];
-        struct addrinfo *addr = _addrinfo;
-        while (addr->ai_next != 0) {
-            if (addr->ai_socktype == SOCK_DGRAM) {
-                std::memset(_address, 0, INET6_ADDRSTRLEN);
-                _ipaddr = inet_ntop(AF_INET,
-                                    &((struct sockaddr_in 
*)addr->ai_addr)->sin_addr,
-                                    _address, INET6_ADDRSTRLEN);
-                dbglogfile << "The IP number for this machine is " << _ipaddr 
<< std::endl;
-            }
-            addr = addr->ai_next;
-        }
-    } else {
-        dbglogfile << "WARNING: Couldn't get the host entry for this machine!" 
<< std::endl;
-    }
+Tcputil::Tcputil(const std::string &host) : Tcputil(host, DEFAULTPORT)
+{
+    DEBUGLOG_REPORT_FUNCTION;
+}
+
+Tcputil::Tcputil(const std::string &host, short port)
+    :_service(0),
+     _proto(0),
+     _hostname("localhost")
+{
+    DEBUGLOG_REPORT_FUNCTION;
+    std::string portstr = std::to_string(port);
+    _hostname = host;
+
+#if 0
+    dbglogfile << "Has " << numberOfInterfaces()
+               << " interfaces, using default one" << std::endl;
+#endif
+    //_proto = getprotobyname("tcp");
+    _proto = getprotobynumber(IPPROTO_IP);
+
+//    if (!getAddrInfo(host, port)) {
+//        dbglogfile << "WARNING: Couldn't get address info for this machine!" 
<< std::endl;
+//    }
     
-    _service = getservbyport(DEFAULTPORT, "tcp");
+    _service = getservbyport(htons(port), _proto->p_name);
     if (_service) {
         dbglogfile <<  "Found service file entry for " << _service->s_name << 
std::endl;
-        _proto = getprotobyname(_service->s_proto);
-        if (_proto) {
-            dbglogfile << "The proto number for " << _proto->p_name
-                       << " is " << _proto->p_proto << std::endl;
-        } else {
-            dbglogfile << "WARNING: Couldn't get the host entry for this 
machine!" << std::endl;
-        }
     } else {
-        dbglogfile << "Services file entry for port " << DEFAULTPORT << " was 
not found!" << std::endl;
+        dbglogfile << "Services file entry for port " << DEFAULTPORT << " was 
not found, using defaults" << std::endl;
     }
+}
 
+struct addrinfo *
+Tcputil::getAddrInfo(const std::string& hostname, std::uint16_t port)
+{
+    DEBUGLOG_REPORT_FUNCTION;
+
+    struct addrinfo hints, *ans = nullptr;
+    ::memset(&hints, 0, sizeof(struct addrinfo));
+
+    //hints.ai_family = AF_UNSPEC;    // Allow IPv4 or IPv6
+    hints.ai_family = AF_INET;  // Allow IPv4 only for now
+    hints.ai_flags = 0;
+    //hints.ai_flags = AI_PASSIVE;
+    hints.ai_protocol = _proto->p_proto;
+    //hints.ai_protocol = 0; // any protocol
+    //hints.ai_socktype = SOCK_DGRAM; // UDP
+    hints.ai_socktype = SOCK_STREAM; // TCP
+
+    _hostname = hostname;
+    std::string portstr = std::to_string(port);
+    int ret = ::getaddrinfo(hostname.c_str(), portstr.c_str(), &hints, &ans);
+    if (ret != 0) {
+        std::cerr << "ERROR: getaddrinfo(" << hostname << ") failed! "
+                  << gai_strerror(ret) << std::endl;
+        return nullptr;
+    }
+
+    // convert the linked list to an array to make it easier to access.
+    struct addrinfo *addr = ans;
+    if (addr->ai_next == 0) {
+        _addrinfo.push_back(addr);
+    }
+    while (addr->ai_next != 0) {
+        std::string str;
+        dbglogfile << "The IP number for this connection is " << printIP(addr, 
str) << std::endl;
+        _addrinfo.push_back(addr);
+        addr = addr->ai_next;
+    }
+
+    return ans;
 }
 
+void
+Tcputil::getInterfaces(void) {
+    // DEBUGLOG_REPORT_FUNCTION;
+
+    struct ifaddrs *addrs,*tmp;
+    char address[INET6_ADDRSTRLEN];
+    std::string str;
+
+    getifaddrs(&addrs);
+    tmp = addrs;
+    while (tmp) {
+        if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_PACKET) {
+            struct ipNode *ip = new ipNode;
+            std::memset(address, 0, INET6_ADDRSTRLEN);
+            struct sockaddr_in *sa = reinterpret_cast<struct sockaddr_in 
*>(tmp->ifa_addr);
+            inet_ntop(AF_INET, &sa->sin_addr, address, INET6_ADDRSTRLEN);
+            ip->ipstr = address;
+            //std::memcpy((void *)&ip->saddr, (void *)tmp->ifa_addr, 
sizeof(struct sockaddr));
+            _nics[tmp->ifa_name] = ip;
+        }
+        tmp = tmp->ifa_next;
+    }
+    freeifaddrs(addrs);
+};
+
 Tcputil::~Tcputil(void)
 {
-    freeaddrinfo(_addrinfo);
+    DEBUGLOG_REPORT_FUNCTION;
+
+    std::map<std::string, struct addrinfo *>::iterator it;
+//    for (it = _addrinfo.begin(); it != _addrinfo.end(); it++) {
+//        freeaddrinfo(*it);
+//    }
 }
 
 struct servent *
 Tcputil::lookupService(const std::string &name, const std::string &protocol)
 {
+    DEBUGLOG_REPORT_FUNCTION;
+
     // Get the service entry from  /etc/services for this 
-    _service = getservbyname(name.c_str(), protocol.c_str());
+    struct servent *serv = getservbyname(name.c_str(), protocol.c_str());
 
-    if (_service) {
+    if (serv) {
         dbglogfile <<  "Found service file entry for " << name << std::endl;
     } else {
         dbglogfile << "Services file entry " << name << " was not found!" << 
std::endl;
     }
 
-    return _service;
+    return serv;
 }
 
-// Description: Get the number of ethernet interfaces on this machine. Some
-//              operating systems, like Solaris, support a ioctl()
-//              specifically for discovering the number of interfaces,
-//              so it exists, use that instead of SIOCGIFCONF.
-int
-Tcputil::numberOfInterfaces(void)
+void
+Tcputil::dump(void)
 {
-    int fd, count = 0;
-#ifdef SIOCGLIFNUM
-    struct lifnum ln;
-#else
-    char   buf[150], *cp, *cplim;
-    struct ifconf ifc;
-    struct ifreq *ifr;
-#endif
-    if (0 > (fd = socket(AF_INET, SOCK_DGRAM,0))) {
-        dbglogfile << "WARNING: Couldn't get file descriptor for AF_INET 
socket!" << std::endl;
-        return -1;
-    }
-#ifdef SIOCGLIFNUM
-    // use AF_INET for IPv4 only or AF_INET6 for IPv6 only
-    // note: if using AF_UNSPEC, some interface names may appear twice,
-    //       once for IPv4 and once for IPv6
-    ln.lifn_family = AF_UNSPEC;
-    ln.lifn_flags = ln.lifn_count=0;
-
-
-    if(ioctl(fd,SIOCGLIFNUM,&ln) == -1) {
-        dbglogfile << "Couldn't get ethernet interface data!: %s\n"
-                   << strerror(errno) << std::endl;
-        return -1;
-    }
+    DEBUGLOG_REPORT_FUNCTION;
 
-    dbglogfile << "There are " <<  << ln.lifn_count " ethernet interfaces." << 
std::endl;
+    std::cerr << "Hostname for this connection is: " << _hostname << std::endl;
 
-    return ln.lifn_count;
-#else
-    ifc.ifc_len = sizeof(buf);
-    ifc.ifc_req = (struct ifreq *)buf;
-    
-    if(ioctl(fd, SIOCGIFCONF, &ifc) == -1) {
-        dbglogfile << "Couldn't get ethernet interface data!: %s"
-                   << strerror(errno) << std::endl;
-        return -1;
+    std::map<std::string, struct ipNode *>::iterator nit;
+    for (nit = _nics.begin(); nit != _nics.end(); nit++) {
+        std::cerr << "\tInterface: " << nit->first << " @ " << 
nit->second->ipstr << std::endl;
+    }
+
+    // dump servent data
+    if (_service) {
+        std::cerr << "Service data:" << std::endl;
+        //std::cerr << "\t" << _service->s_name << std::endl;
+        //char **s_aliases;
+        std::cerr << "\t" << _service->s_port << std::endl;
+        std::cerr << "\t" << _service->s_proto << std::endl;
     }
     
-    ifr = ifc.ifc_req;
-    cplim = buf + ifc.ifc_len;
-    for (cp = buf; cp < cplim; cp += sizeof(ifr->ifr_name) + 
sizeof(ifr->ifr_addr)) {
-        ifr = (struct ifreq *) cp;
-#ifdef NET_DEBUG
-        dbglogfile << "interface name is: " << ifr->ifr_name << std::endl;
-#endif
-        count++;
+    if (_proto) {
+        std::cerr << "Proto data:" << std::endl;
+        // dump protoent data
+        //char **p_aliases;
+        std::cerr << "\tNumber: " << (_proto->p_proto ? _proto->p_proto : 0)
+                  <<  " (" << (_proto->p_name ? _proto->p_name : "none") << ")"
+                  << std::endl;
     }
-#endif
 
-    return count;
+    // Dump addrinfo data
+    const std::string st[] = { "UNSPEC", "SOCK_STREAM", "SOCK_DGRAM", 
"SOCK_RAW" };
+    const std::string ft[] = { "AF_UNSPEC", "AF_LOCAL", "AF_INET", "AF_AX25",
+                               "AF_IPX", "AF_APPLETALK", "AF_NETROM",
+                               "AF_BRIDGE", "AF_ATMPVC", "AF+X25", "AF_INET6" 
};
+    // We only care about these two values
+    char *pt[18];
+    pt[getprotobyname("tcp")->p_proto] = "tcp";
+    pt[getprotobyname("udp")->p_proto] = "udp";
+
+    std::cerr << "Addrinfo data has: " << _addrinfo.size() << " entries" << 
std::endl;
+    std::vector<struct addrinfo *>::iterator ait;
+    for (ait = _addrinfo.begin(); ait != _addrinfo.end(); ait++) {
+        if ((*ait)->ai_canonname != 0) {
+            std::cerr << "\Hostname: " << (*ait)->ai_canonname << std::endl;
+        }
+        std::cerr << "\tFlags: " << (*ait)->ai_flags << std::endl;
+        std::cerr << "\tFamily: " << ft[(*ait)->ai_family] << std::endl;
+        std::cerr << "\tsocktype: " << st[(*ait)->ai_socktype] << std::endl;
+        std::cerr << "\tprotocol: " << pt[(*ait)->ai_protocol]<< std::endl;
+        //socklen_t _addrinfo->ai_addrlen;
+        //sockaddr _addrinfo->ai_addr;
+        //std::cerr << *ait->ai_canonname << std::endl;
+    }
 }
 
 // local Variables:
diff --git a/lib/tcputil.h b/lib/tcputil.h
index 6bc0be6..dfc4a76 100644
--- a/lib/tcputil.h
+++ b/lib/tcputil.h
@@ -24,6 +24,7 @@
 # include "config.h"
 #endif
 
+#include <ifaddrs.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/param.h>
@@ -32,13 +33,25 @@
 #include <netdb.h>
 #include <cstring>
 #include <vector>
+#include <map>
 
 #include "log.h"
 #include "err.h"
 
+extern const std::string DEFAULTPROTO;
+extern const short DEFAULTPORT;
+
 class Tcputil {
 public:
+    // The interface name is the index field for an array of this data
+    struct ipNode {
+        std::string ipstr;
+        struct saddr;
+    };
+
     Tcputil();
+    Tcputil(const std::string &host);
+    Tcputil(const std::string &host, short port);
     ~Tcputil();
     
     // This gets the servent data that contains the port
@@ -49,19 +62,44 @@ public:
     };
     struct servent *lookupService(const std::string &name,
                                   const std::string &protocol);
-    int numberOfInterfaces(void);
-    // Accessors
-    short getPort(void) { return -1; }; // FIXME
-    int getProtocol(void) { return _addrinfo->ai_protocol; };
-    std::string &getHostname(void) { return _hostname; };
-    std::string &getIP(void) { return _ipaddr; };
+    struct addrinfo *getAddrInfo(void) {
+        return getAddrInfo("localhost", DEFAULTPORT);
+    };
+    struct addrinfo *getAddrInfo(const std::string& hostname) {
+        return getAddrInfo(hostname, DEFAULTPORT);
+    };
+    struct addrinfo *getAddrInfo(const std::string& hostname, std::uint16_t 
port);
+
+    const std::string &printIP(struct addrinfo *addr, std::string &str) {
+        char address[INET6_ADDRSTRLEN];
+        std::memset(address, 0, INET6_ADDRSTRLEN);
+        inet_ntop(AF_INET, &((struct sockaddr_in *)addr->ai_addr)->sin_addr,
+                  address, INET6_ADDRSTRLEN);
+        str = address;
+        return str;
+    };
+
+    void getInterfaces(void);
+    
+    int numberOfInterfaces(void) {
+        if (_nics.size() == 0) {
+            getInterfaces();
+        }
+        return _nics.size();
+    };
+
+    std::string getHostname() {
+        return _hostname;
+    };
+    
+    void dump(void);
     
 protected:
-    std::string        _hostname;
-    std::string        _ipaddr;
-    struct servent     *_service;
-    struct protoent    *_proto;
-    struct addrinfo    *_addrinfo;
+    std::string                    _hostname;
+    struct servent *               _service;
+    struct protoent *              _proto;
+    std::vector<struct addrinfo *> _addrinfo;
+    std::map<std::string, struct ipNode *> _nics;
 };
 
 // EOF __TCPUTIL_H__

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

Summary of changes:
 lib/tcpip.cc   | 162 ++++++++++++++++---------------------
 lib/tcpip.h    |   3 +
 lib/tcputil.cc | 250 +++++++++++++++++++++++++++++++++++----------------------
 lib/tcputil.h  |  60 +++++++++++---
 4 files changed, 272 insertions(+), 203 deletions(-)


hooks/post-receive
-- 
powerguru



reply via email to

[Prev in Thread] Current Thread [Next in Thread]