Exemplo n.º 1
0
static gboolean
afinet_dd_setup_addresses(AFSocketDestDriver *s)
{
  AFInetDestDriver *self = (AFInetDestDriver *) s;

  if (!afsocket_dd_setup_addresses_method(s))
    return FALSE;

  g_sockaddr_unref(self->super.bind_addr);
  g_sockaddr_unref(self->super.dest_addr);

  if (!resolve_hostname_to_sockaddr(&self->super.bind_addr, self->super.transport_mapper->address_family, self->bind_ip))
    return FALSE;

  if (self->bind_port)
    g_sockaddr_set_port(self->super.bind_addr, afinet_lookup_service(self->super.transport_mapper, self->bind_port));

  if (!resolve_hostname_to_sockaddr(&self->super.dest_addr, self->super.transport_mapper->address_family, self->hostname))
    return FALSE;

  if (!self->dest_port)
    {
      const gchar *port_change_warning = transport_mapper_inet_get_port_change_warning(self->super.transport_mapper);

      if (port_change_warning)
        {
          msg_warning(port_change_warning,
                      evt_tag_str("id", self->super.super.super.id));
        }
    }

  g_sockaddr_set_port(self->super.dest_addr, _determine_port(self));

  return TRUE;
}
Exemplo n.º 2
0
static void
assert_hostname_to_sockaddr_fails(gint family, const gchar *hostname)
{
  GSockAddr *sa = NULL;
  gboolean result;

  result = resolve_hostname_to_sockaddr(&sa, family, hostname);
  g_sockaddr_unref(sa);

  assert_null(sa, "returned sockaddr is non-NULL");
  assert_false(result, "unexpected success returned");
}
Exemplo n.º 3
0
static void
assert_hostname_to_sockaddr(gint family, const gchar *hostname, const gchar *expected_ip)
{
  GSockAddr *sa = NULL;
  gchar ip[64];
  gboolean result;

  result = resolve_hostname_to_sockaddr(&sa, family, hostname);
  if (sa)
    {
      g_sockaddr_format(sa, ip, sizeof(ip), GSA_ADDRESS_ONLY);
      g_sockaddr_unref(sa);
    }

  assert_true(result, "unexpected error return");
  assert_true(sa != NULL, "sockaddr can't be NULL for successful returns");
  assert_string(ip, expected_ip, "resolved address mismatch");
}
Exemplo n.º 4
0
int
stomp_connect(stomp_connection **connection_ref, char *hostname, int port)
{
  stomp_connection *conn;

  conn = g_new0(stomp_connection, 1);

  conn->socket = socket(AF_INET, SOCK_STREAM, 0);
  if (conn->socket == -1)
    {
      msg_error("Failed to create socket!", NULL);
      return FALSE;
    }

  if (!resolve_hostname_to_sockaddr(&conn->remote_sa, AF_INET, hostname))
    {
      msg_error("Failed to resolve hostname in stomp driver",
                evt_tag_str("hostname", hostname),
                NULL);

      return FALSE;
    }

  g_sockaddr_set_port(conn->remote_sa, port);
  if (!g_connect(conn->socket, conn->remote_sa))
    {
      msg_error("Stomp connection failed",
                evt_tag_str("host", hostname),
                NULL);
      _stomp_connection_free(conn);
      return FALSE;
    }

  (*connection_ref) = conn;

  return TRUE;
};