Beispiel #1
0
static void
test_ipv4 (void)
{
  NiceAddress addr;
  NiceAddress other;
  gchar str[NICE_ADDRESS_STRING_LEN];

  nice_address_init (&addr);
  nice_address_init (&other);
  nice_address_set_ipv4 (&addr, 0x01020304);
  g_assert (addr.s.ip4.sin_family == AF_INET);

  nice_address_to_string (&addr, str);
  g_assert (0 == strcmp (str, "1.2.3.4"));

  nice_address_to_string (&addr, str);

  /* same address */
  nice_address_set_ipv4 (&other, 0x01020304);
  g_assert (TRUE == nice_address_equal (&addr, &other));

  /* from sockaddr_in */
  nice_address_set_port (&other, 9876); /* in native byte order */
  other.s.ip4.sin_family = AF_INET;
  nice_address_set_from_string (&addr, "1.2.3.4");
  nice_address_set_port (&addr, 9876); /* in native byte order */
  nice_address_to_string (&addr, str);
  nice_address_to_string (&other, str);
  g_assert (TRUE == nice_address_equal (&addr, &other));

  /* different IP */
  nice_address_set_ipv4 (&other, 0x01020305);
  g_assert (FALSE == nice_address_equal (&addr, &other));

  /* different port */
  nice_address_set_ipv4 (&other, 0x01020304);
  nice_address_set_port (&addr, 1);
  g_assert (FALSE == nice_address_equal (&addr, &other));

  /* test private address check */
  {
    NiceAddress *heap_addr = nice_address_new ();
    g_assert (nice_address_set_from_string (heap_addr, "127.0.0.1") == TRUE);
    g_assert (nice_address_is_private (heap_addr) == TRUE);
    g_assert (nice_address_set_from_string (heap_addr, "127.0.0.1.1") != TRUE);
    nice_address_free (heap_addr);
  }
}
Beispiel #2
0
int
main (void)
{
  NiceAgent *agent;
  NiceAddress addr;
  guint stream;

  nice_address_init (&addr);
  g_type_init ();
  g_thread_init(NULL);

  loop = g_main_loop_new (NULL, FALSE);

  agent = nice_agent_new (g_main_loop_get_context (loop), NICE_COMPATIBILITY_RFC5245);
  nice_address_set_ipv4 (&addr, 0x7f000001);
  nice_agent_add_local_address (agent, &addr);
  stream = nice_agent_add_stream (agent, 1);
  nice_agent_gather_candidates (agent, stream);

  // attach to default main context
  nice_agent_attach_recv (agent, stream, NICE_COMPONENT_TYPE_RTP,
      g_main_loop_get_context (loop), recv_cb, GUINT_TO_POINTER (42));

    {
      NiceCandidate *candidate;
      GSList *candidates, *i;

      candidates = nice_agent_get_local_candidates (agent, 1, 1);
      candidate = candidates->data;

      nice_socket_send (candidate->sockptr, &(candidate->addr), 6, "\x80hello");
      for (i = candidates; i; i = i->next)
        nice_candidate_free ((NiceCandidate *) i->data);
      g_slist_free (candidates);
    }

  g_main_loop_run (loop);

  g_object_unref (agent);
  return 0;
}