Esempio n. 1
0
static void
query_cb_err_print(const int err)
{
    if (err == DNS_ERR_UNKNOWN || err == DNS_ERR_TRUNCATED) {
        fprintf(stderr, "Response might be truncated.\n"
                "If you just started dnscrypt-proxy, this is expected; you may want to retry.\n");
    } else {
        fprintf(stderr, "[%s]\n", evdns_err_to_string(err));
    }
    exit(1);
}
Esempio n. 2
0
static void hub_lookup_event(int result, char type, int count, int ttl,
                             void *addresses, void *user_data)
{
    hub_connect_data_t *hcd = user_data;
    return_if_fail(hcd);

    if(result == DNS_ERR_NONE)
    {
        struct in_addr *addrs = addresses;
        return_if_fail(addrs);
        return_if_fail(count >= 1);
        hub_connect_async(hcd, &addrs[0]);
    }
    else
    {
        const char *errmsg = evdns_err_to_string(result);
        WARNING("Failed to lookup '%s': %s", hcd->address, errmsg);
        ui_send_status_message(NULL, hcd->address,
                               "Failed to lookup '%s': %s", hcd->address, errmsg);
    }
}
Esempio n. 3
0
int hub_connect(const char *hubname, const char *nick, const char *email,
                const char *description, const char *speed, bool passive,
                const char *password, const char *encoding)
{
    return_val_if_fail(nick, -1);
    return_val_if_fail(hubname, -1);

    char *host = 0;
    int port = 0;
    if(split_host_port(hubname, &host, &port) != 0)
    {
        return -1;
    }
    else if(port < 0)
    {
        ui_send_status_message(NULL, hubname,
                               "Invalid port in hub address: %s", hubname);
        free(host);
        return -1;
    }
    else if(port == 0)
    {
        port = 411; /* default port */
    }

    ui_send_status_message(NULL, hubname, "Connecting to %s...", hubname);

    hub_connect_data_t *hcd = calloc(1, sizeof(hub_connect_data_t));
    hcd->nick = strdup(nick);
    hcd->email = xstrdup(email);
    hcd->description = xstrdup(description);
    hcd->speed = xstrdup(speed);
    hcd->address = strdup(hubname);
    hcd->passive = passive;
    hcd->password = xstrdup(password);
    hcd->encoding = xstrdup(encoding);
    hcd->port = port;

    struct in_addr xaddr;
    if(inet_aton(host, &xaddr))
    {
        /* host already given as an IP address */
        hub_connect_async(hcd, &xaddr);
        free(host);
    }
    else
    {
        int rc = evdns_resolve_ipv4(host, 0, hub_lookup_event, hcd);
        free(host);
        if(rc != DNS_ERR_NONE)
        {
            WARNING("Failed to lookup '%s': %s",
                    hubname, evdns_err_to_string(rc));
            ui_send_status_message(NULL, hubname, "Failed to lookup '%s': %s",
                                   hubname, evdns_err_to_string(rc));
            hcd_free(hcd);
            return -1;
        }
    }

    return 0;
}
Esempio n. 4
0
static void
query_cb_err_print(const int err)
{
    fprintf(stderr, "[%s]\n", evdns_err_to_string(err));
    exit(1);
}