[omniORB] omniORB 4.0.2 & omniNames startup
Craig Rodrigues
crodrigu at bbn.com
Fri Jan 23 13:59:21 GMT 2004
On Wed, Jan 21, 2004 at 05:11:09PM +0000, Duncan Grisby wrote:
> I'd welcome a patch to configure.ac and tcpTransportImpl.cc that
> implemented that. I don't have any systems with it available.
Hi,
This patch users getifaddrs() to get the list of
network interfaces.
Tested on RedHat Linux 9 and FreeBSD 5.2.
--
Craig Rodrigues Distributed Systems and Logistics, Office 6/325A
crodrigu at bbn.com BBN Technologies, a Verizon company
(617) 873-4725 Cambridge, MA
Index: configure.ac
===================================================================
RCS file: /cvsroot/omniorb/omni/Attic/configure.ac,v
retrieving revision 1.1.2.21
diff -u -u -r1.1.2.21 configure.ac
--- configure.ac 21 Nov 2003 16:30:23 -0000 1.1.2.21
+++ configure.ac 23 Jan 2004 17:47:38 -0000
@@ -36,6 +36,7 @@
AC_CHECK_HEADERS(errno.h fcntl.h netdb.h signal.h stdlib.h string.h strings.h)
AC_CHECK_HEADERS(unistd.h nan.h sys/if.h sys/ioctl.h sys/param.h sys/time.h)
+AC_CHECK_HEADERS(ifaddrs.h)
AC_HEADER_TIME
Index: src/lib/omniORB/orbcore/tcp/tcpTransportImpl.cc
===================================================================
RCS file: /cvsroot/omniorb/omni/src/lib/omniORB/orbcore/tcp/Attic/tcpTransportImpl.cc,v
retrieving revision 1.1.2.19
diff -u -u -r1.1.2.19 tcpTransportImpl.cc
--- src/lib/omniORB/orbcore/tcp/tcpTransportImpl.cc 6 Nov 2003 10:18:39 -0000 1.1.2.19
+++ src/lib/omniORB/orbcore/tcp/tcpTransportImpl.cc 23 Jan 2004 17:47:40 -0000
@@ -108,6 +108,10 @@
# include <net/if.h>
#endif
+#if defined(HAVE_IFADDRS_H)
+# include <ifaddrs.h>
+#endif
+
#if defined(NTArchitecture)
# include <libcWrapper.h>
# include <ws2tcpip.h>
@@ -224,6 +228,8 @@
/////////////////////////////////////////////////////////////////////////
#if defined(__vxWorks__)
static void vxworks_get_ifinfo(omnivector<const char*>& ifaddrs);
+#elif defined(HAVE_IFADDRS_H)
+static void ifaddrs_get_ifinfo(omnivector<const char*>& addrs);
#elif defined(UnixArchitecture)
static void unix_get_ifinfo(omnivector<const char*>& ifaddrs);
#elif defined(NTArchitecture)
@@ -237,6 +243,8 @@
#if defined(__vxWorks__)
vxworks_get_ifinfo(ifAddresses);
+#elif defined(HAVE_IFADDRS_H)
+ ifaddrs_get_ifinfo(ifAddresses);
#elif defined(UnixArchitecture)
unix_get_ifinfo(ifAddresses);
#elif defined(NTArchitecture)
@@ -255,10 +263,46 @@
const tcpTransportImpl _the_tcpTransportImpl;
-/////////////////////////////////////////////////////////////////////////
-#if defined(UnixArchitecture)
+/////////////////////////////////////////////////////////////////////////
+#if defined(HAVE_IFADDRS_H)
+static
+void ifaddrs_get_ifinfo(omnivector<const char*>& addrs) {
+
+ struct ifaddrs *ifa_list;
+
+ if ( getifaddrs(&ifa_list) < 0 ) {
+ if ( omniORB::trace(1) ) {
+ omniORB::logger log;
+ log << "Warning: getifaddrs() failed.\n"
+ << "Unable to obtain the list of all interface addresses.\n";
+ }
+ return;
+ }
-# if !defined(__vxWorks__)
+ struct ifaddrs *p;
+ for (p = ifa_list; p != 0; p = p->ifa_next) {
+ if ( p->ifa_addr->sa_family == AF_INET ) {
+ struct sockaddr_in* iaddr = (struct sockaddr_in*)p->ifa_addr;
+ CORBA::String_var s;
+ s = tcpConnection::ip4ToString(iaddr->sin_addr.s_addr);
+ addrs.push_back(s._retn());
+ }
+ }
+ freeifaddrs(ifa_list);
+
+ if ( orbParameters::dumpConfiguration || omniORB::trace(20) ) {
+ omniORB::logger log;
+ omnivector<const char*>::iterator i = addrs.begin();
+ omnivector<const char*>::iterator last = addrs.end();
+ log << "My addresses are: \n";
+ while ( i != last ) {
+ log << "omniORB: " << (const char*)(*i) << "\n";
+ i++;
+ }
+ }
+}
+
+#elif defined(UnixArchitecture) && !defined(__vxWorks__)
#ifdef __aix__
# define OMNI_SIOCGIFCONF OSIOCGIFCONF
@@ -333,7 +378,7 @@
}
/////////////////////////////////////////////////////////////////////////
-# else // __vxWorks__
+#elif defined(__vxWorks__)
void vxworks_get_ifinfo(omnivector<const char*>& ifaddrs) {
const int iMAX_ADDRESS_ENTRIES = 50;
@@ -419,9 +464,8 @@
}
close (s);
}
-# endif // __vxWorks__
-#endif // UnixArchitecture
+#endif
/////////////////////////////////////////////////////////////////////////
More information about the omniORB-list
mailing list