Beispiel #1
0
/*
 * If prefix b is contained in prefix a, then return TRUE. Otherwise return FALSE.
 * If both prefixs are the same it also returns TRUE
 */
int is_prefix_b_part_of_a (
        lisp_addr_t a_prefix,
        int a_prefix_length,
        lisp_addr_t b_prefix,
        int b_prefix_length)
{
    lisp_addr_t a_network_addr;
    lisp_addr_t b_network_addr_prefix_a;

    if (a_prefix.afi != b_prefix.afi){
        return FALSE;
    }

    if (a_prefix_length > b_prefix_length){
        return FALSE;
    }

    a_network_addr = get_network_address(a_prefix, a_prefix_length);
    b_network_addr_prefix_a = get_network_address(b_prefix, a_prefix_length);

    if (compare_lisp_addr_t (&a_network_addr, &b_network_addr_prefix_a) == 0){
        return (TRUE);
    }else{
        return (FALSE);
    }
}
Beispiel #2
0
// TODO(kashihara): support hostaddr can be hostname not only IP address
string get_default_v4_address(string hostaddr) {
  string address;

  const address_list addrs = get_network_address();
  for (address_list::const_iterator it = addrs.begin(), end = addrs.end();
      it != end; ++it) {
    jubatus::util::lang::shared_ptr<network_address> a(*it);
    if (a->v6()) {
      continue;
    }
    address = a->address();
    if (!hostaddr.empty() && address == hostaddr) {
      break;
    }

    if (!a->loopback()) {
      break;
    }
  }

  if (!hostaddr.empty() && address != hostaddr) {
    LOG(WARNING) << "Use server address as '" << address << "' because '"
                 << hostaddr << "' missing";
  }

  return address;
}
gchar*
calculate_network6(const gchar* ipv6, int prefix, gchar *calculated_network)
{
  struct in6_addr network;
  struct in6_addr address;

  memset(&network, 0, sizeof(struct in6_addr));

  inet_pton(AF_INET6, ipv6, &address);
  get_network_address((unsigned char *)&address, prefix, &network);
  inet_ntop(AF_INET6, &network, calculated_network, INET6_ADDRSTRLEN);
  return calculated_network;
}