Exemple #1
0
void
test_channel_local_addr_get_set_unset(void) {
    lagopus_result_t ret;
    struct channel *channel;
    struct addrunion addr  = {0,{{0}}};
    struct addrunion addr1 = {0,{{0}}};

    channel = s_create_data_channel();
    addrunion_ipv4_set(&addr, "127.0.0.1");
    ret = channel_local_addr_set(channel, &addr);
    TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                              "channel_local_addr_set() error.");

    ret = channel_local_addr_get(channel, &addr1);
    TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                              "channel_local_addr_get() error.");
    TEST_ASSERT_EQUAL_MEMORY_MESSAGE(&addr, &addr1, sizeof(addr),
                                     "channel_local_addr_get() addr error");

    ret = channel_local_addr_unset(channel);
    TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                              "channel_local_addr_unset() error.");

    ret = channel_local_addr_get(channel, &addr1);
    TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret,
                              "channel_local_addr_get() error.");
    addrunion_ipv4_set(&addr, "0.0.0.0");
    TEST_ASSERT_EQUAL_MEMORY_MESSAGE(&addr, &addr1, sizeof(addr),
                                     "channel_local_addr_get() addr  error");

    session_destroy(channel_session_get(channel));
    free(channel);
}
Exemple #2
0
lagopus_result_t
channel_mgr_channel_local_addr_get(const char *channel_name,
                                   lagopus_ip_address_t **local_addr) {
  char ipaddr[INET6_ADDRSTRLEN+1];
  lagopus_result_t ret;
  struct channel *chan;
  struct addrunion addr = {0};

  ret = channel_mgr_channel_lookup_by_name(channel_name, &chan);
  if (ret != LAGOPUS_RESULT_OK) {
    return ret;
  }

  ret = channel_local_addr_get(chan, &addr);
  if (ret != LAGOPUS_RESULT_OK) {
    return ret;
  }

  if (addrunion_ipaddr_str_get(&addr, ipaddr, sizeof(ipaddr)) == NULL) {
    return LAGOPUS_RESULT_ANY_FAILURES;
  }

  ret = lagopus_ip_address_create(ipaddr,
                                  addrunion_af_get(&addr) == AF_INET ? true : false, local_addr);
  if (ret != LAGOPUS_RESULT_OK) {
    return ret;
  }

  return ret;
}