certi-cvs
[Top][All Lists]
Advanced

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

[certi-cvs] certi libCERTI/SocketUDP.cc libCERTI/SocketUDP....


From: CERTI CVS commits
Subject: [certi-cvs] certi libCERTI/SocketUDP.cc libCERTI/SocketUDP....
Date: Fri, 27 Sep 2013 13:04:33 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Eric NOULARD <erk>      13/09/27 13:04:33

Modified files:
        libCERTI       : SocketUDP.cc SocketUDP.hh Socket.hh 
        RTIG           : RTIG.cc 

Log message:
        Fixes
        bug #23360 : RTIA UDP socket being bound to `localhost` address
        bug #35955 : RTIG listen on all interfaces
        
        UDP as well as TCP should obey the new -l option of RTIG.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketUDP.cc?cvsroot=certi&r1=3.31&r2=3.32
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketUDP.hh?cvsroot=certi&r1=3.15&r2=3.16
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Socket.hh?cvsroot=certi&r1=3.21&r2=3.22
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/RTIG.cc?cvsroot=certi&r1=3.71&r2=3.72

Patches:
Index: libCERTI/SocketUDP.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketUDP.cc,v
retrieving revision 3.31
retrieving revision 3.32
diff -u -b -r3.31 -r3.32
--- libCERTI/SocketUDP.cc       4 Sep 2013 07:50:52 -0000       3.31
+++ libCERTI/SocketUDP.cc       27 Sep 2013 13:04:32 -0000      3.32
@@ -24,10 +24,6 @@
 #include <cstring>
 #include <cstdio>
 
-#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 4096
-#endif
-
 #ifdef _WIN32
 #include "SocketTCP.hh"
 #else
@@ -140,40 +136,24 @@
 // ----------------------------------------------------------------------------
 //! create an UDP server.
 void
-SocketUDP::createUDPServer(unsigned int port)
+SocketUDP::createUDPServer(unsigned int port, in_addr_t addr)
     throw (NetworkError, NetworkSignal)
 {
   assert(!_est_init_udp);
 
-  char localhost[MAXHOSTNAMELEN+1] ;
-  struct hostent * hp_local=NULL;
-
   // Building Local Address
   memset((struct sockaddr_in *) &sock_local, 0, sizeof(struct sockaddr_in));
 
-  gethostname(localhost, MAXHOSTNAMELEN);
-
-  hp_local = (struct hostent *) gethostbyname(localhost);
-  if (NULL == hp_local)
-    {
-        throw NetworkError(stringize()
-            << "gethostbyname gave NULL answer for hostname <"
-            << localhost
-            << "> with error <" << strerror(errno) << ">");
-    }
-
-   memcpy((char *) &sock_local.sin_addr,(char *)hp_local->h_addr, 
hp_local->h_length);
-   sock_local.sin_family = hp_local->h_addrtype ;
+   sock_local.sin_addr.s_addr   = addr;
+   sock_local.sin_family = AF_INET;
    sock_local.sin_port   = htons((u_short)port);
 
-if (!open())
-       {
+   if (!open()) {
        perror("SocketUDP: Open");
        throw NetworkError("Cannot open UDP Socket");
        }
 
-if (!bind())
-       {
+   if (!bind()) {
        perror("SocketUDP: Bind");
        throw NetworkError("Cannot bind UDP Socket");
        }

Index: libCERTI/SocketUDP.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/SocketUDP.hh,v
retrieving revision 3.15
retrieving revision 3.16
diff -u -b -r3.15 -r3.16
--- libCERTI/SocketUDP.hh       4 Sep 2013 07:50:54 -0000       3.15
+++ libCERTI/SocketUDP.hh       27 Sep 2013 13:04:33 -0000      3.16
@@ -50,7 +50,7 @@
     virtual void createConnection(const char *server_name, unsigned int port)
         throw (NetworkError);
 
-       void createUDPServer(unsigned int port)
+       void createUDPServer(unsigned int port, in_addr_t addr = INADDR_ANY)
        throw (NetworkError, NetworkSignal);
 
        void attach(int socket_ouvert, unsigned long Adresse, unsigned int port)
@@ -65,7 +65,7 @@
        int bind();
        int open();
 
-       bool PhysicalLink ; ///< tak indicating physical or logical link
+       bool PhysicalLink ; ///< tag indicating physical or logical link
 
        SOCKET _socket_udp;
        struct sockaddr_in sock_local ;

Index: libCERTI/Socket.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Socket.hh,v
retrieving revision 3.21
retrieving revision 3.22
diff -u -b -r3.21 -r3.22
--- libCERTI/Socket.hh  4 Sep 2013 07:56:52 -0000       3.21
+++ libCERTI/Socket.hh  27 Sep 2013 13:04:33 -0000      3.22
@@ -39,6 +39,11 @@
 typedef int SOCKET;
 #endif
 
+#ifndef MAXHOSTNAMELEN
+#define MAXHOSTNAMELEN 4096
+#endif
+
+#include <unistd.h>
 #include <cstring>
 #include <cerrno>
 #include <string>
@@ -92,8 +97,8 @@
     /**
      * This function builds an IP address out of an hostname.
      */
-    static in_addr_t host2addr(const std::string& hostName) throw 
(NetworkError) {
-        in_addr_t retaddr=0;
+    static void host2addr(const std::string& hostName, in_addr_t& addr) throw 
(NetworkError) {
+        addr = 0;
         // get host information from server name
         // this may perform DNS query
         struct hostent *hptr = gethostbyname(hostName.c_str());
@@ -104,8 +109,23 @@
                     << hostName
                     << "> with error <" << strerror(errno) << ">");
         }
-        memcpy((void *) &retaddr, (void *) hptr->h_addr, hptr->h_length);
-        return retaddr;
+        memcpy((void *) &addr, (void *) hptr->h_addr, hptr->h_length);;
+    }
+
+    /**
+     * Get the IP address corresponding to the first interface of the host.
+     */
+    static void getMyFirstIPaddr(in_addr_t& addr) throw (NetworkError) {
+        char           name[MAXHOSTNAMELEN+1];
+        /* FIXME gethostname is deprecated
+         * we should use getnameinfo and getaddrinfo
+         */
+        if (0 != gethostname(name,1024)) {
+            throw NetworkError(stringize()
+                                << "gethostname FAILED"
+                                << " with error <" << strerror(errno) << ">");
+        }
+        Socket::host2addr(name,addr);
     }
 };
 

Index: RTIG/RTIG.cc
===================================================================
RCS file: /sources/certi/certi/RTIG/RTIG.cc,v
retrieving revision 3.71
retrieving revision 3.72
diff -u -b -r3.71 -r3.72
--- RTIG/RTIG.cc        24 Sep 2013 14:27:58 -0000      3.71
+++ RTIG/RTIG.cc        27 Sep 2013 13:04:33 -0000      3.72
@@ -457,7 +457,7 @@
 
 void
 RTIG::setListeningIPAddress(const std::string& hostName) throw (NetworkError) {
-    this->listeningIPAddress = Socket::host2addr(hostName);
+    Socket::host2addr(hostName,this->listeningIPAddress);
 }
 
 
@@ -475,10 +475,10 @@
     // listen only on specified interface (if any)
     //  1) listen on interface specified on the command line
     if (this->listeningIPAddress != 0) {
-        udpSocketServer.createUDPServer(udpPort);
+        udpSocketServer.createUDPServer(udpPort, listeningIPAddress);
         tcpSocketServer.createTCPServer(tcpPort, listeningIPAddress);
     }
-    // default case listen on all network interfaces
+    // default case on all network interfaces
     else {
         udpSocketServer.createUDPServer(udpPort);
         tcpSocketServer.createTCPServer(tcpPort);
@@ -1072,4 +1072,4 @@
 
 }} // namespace certi/rtig
 
-// $Id: RTIG.cc,v 3.71 2013/09/24 14:27:58 erk Exp $
+// $Id: RTIG.cc,v 3.72 2013/09/27 13:04:33 erk Exp $



reply via email to

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