Functions

IIOP_Endpoint.cpp File Reference

#include "tao/IIOP_Endpoint.h"
#include "tao/IOPC.h"
#include "tao/debug.h"
#include "tao/ORB_Core.h"
#include "tao/IIOP_Profile.h"
#include "ace/Log_Msg.h"
#include "ace/Guard_T.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_strings.h"
#include "ace/OS_NS_stdio.h"
#include "ace/os_include/os_netdb.h"
#include "ace/Vector_T.h"
#include "ace/ACE.h"
#include "ace/INET_Addr.h"
#include "ace/Sock_Connect.h"
Include dependency graph for IIOP_Endpoint.cpp:

Go to the source code of this file.

Functions

static ACE_CString find_local (const ACE_Vector< ACE_CString > &local_ips, const ACE_CString &pattern)
static void get_ip_interfaces (ACE_Vector< ACE_CString > &local_ips)
static void find_preferred_interfaces (const ACE_CString &host, const ACE_CString &csvPreferred, ACE_Vector< ACE_CString > &preferred)

Function Documentation

static ACE_CString find_local ( const ACE_Vector< ACE_CString > &  local_ips,
const ACE_CString pattern 
) [static]

Definition at line 403 of file IIOP_Endpoint.cpp.

{
  for (size_t i = 0; i < local_ips.size(); ++i)
  {
    ACE_CString ret = local_ips[i];
    if (ACE::wild_match(ret.c_str(), pattern.c_str()))
      return ret;
  }
  return "";
}

static void find_preferred_interfaces ( const ACE_CString host,
const ACE_CString csvPreferred,
ACE_Vector< ACE_CString > &  preferred 
) [static]

Definition at line 458 of file IIOP_Endpoint.cpp.

{
  ACE_Vector<ACE_CString> local_ips;
  get_ip_interfaces(local_ips);
  if (local_ips.size() == 0)
    return;

  // The outer loop steps through each preferred interface directive
  // and chains a new endpoint if the remote interface matches the
  // current endpoint.
  ACE_CString::size_type index = 0;
  while (index < csvPreferred.length())
  {
    ACE_CString::size_type comma = csvPreferred.find(',', index);
    ACE_CString::size_type assign = csvPreferred.find('=', index);

    if (assign == ACE_CString::npos)
    {
      assign = csvPreferred.find(':', index);
      if (assign == ACE_CString::npos)
      {
        ACE_ASSERT(assign != ACE_CString::npos);
        return;
      }
    }

    ACE_CString wild_local;
    if (comma == ACE_CString::npos)
      wild_local = csvPreferred.substr(assign + 1);
    else
      wild_local = csvPreferred.substr(assign + 1, comma - assign - 1);
    ACE_CString wild_remote = csvPreferred.substr(index, assign - index);

    index = comma + 1;

    // For now, we just try to match against the host literally. In
    // the future it might be worthwhile to resolve some aliases for
    // this->host_ using DNS (and possibly reverse DNS) lookups. Then we
    // could try matching against those too.
    if (ACE::wild_match(host.c_str(), wild_remote.c_str(), false))
    {
      // If it's a match, then it means we need to use a
      // local interface that matches wild_local.
      ACE_CString local = find_local(local_ips, wild_local);
      if (local.length() > 0)
      {
        preferred.push_back(local);
      }
      else
      {
        // There is no matching local interface, so we can skip
        // to the next preferred interface directive.
      }
    }
    else
    {
      // The preferred interface directive is for a different
      // remote endpoint.
    }
    if (comma == ACE_CString::npos)
      break;
  }
}

static void get_ip_interfaces ( ACE_Vector< ACE_CString > &  local_ips  )  [static]

Definition at line 428 of file IIOP_Endpoint.cpp.

{
  ACE_INET_Addr* tmp = 0;
  size_t cnt = 0;
  int err = ACE::get_ip_interfaces (cnt, tmp);
  if (err != 0)
    return;
#if defined (ACE_HAS_IPV6)
  char buf[64];
#else /* ACE_HAS_IPV6 */
  char buf[32];
#endif /* !ACE_HAS_IPV6 */
  for (size_t i = 0; i < cnt; ++i)
  {
    const char *s_if = tmp[i].get_host_addr(buf, sizeof (buf));
    ACE_ASSERT(s_if != 0);
    ACE_CString tmp(s_if);
    //ssize_t pos = tmp.find(':');
    //if (pos != ACE_CString::npos)
    //  tmp = tmp.substr(0, pos);
    local_ips.push_back(tmp);
  }
  delete[] tmp;
}

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines