コード例 #1
0
ファイル: resolv.c プロジェクト: janeczku/sniproxy
struct ResolvQuery *
resolv_query(const char *hostname, void (*client_cb)(struct Address *, void *), void (*client_free_cb)(void *), void *client_cb_data) {
    struct dns_ctx *ctx = (struct dns_ctx *)resolv_io_watcher.data;

    /*
     * Wrap udns's call back in our own
     */
    struct ResolvQuery *cb_data = malloc(sizeof(struct ResolvQuery));
    if (cb_data == NULL) {
        err("Failed to allocate memory for DNS query callback data.");
        return NULL;
    }
    cb_data->client_cb = client_cb;
    cb_data->client_free_cb = client_free_cb;
    cb_data->client_cb_data = client_cb_data;

    /* Just resolving A records for now */
    cb_data->query = dns_submit_a4(ctx,
            hostname, 0,
            dns_query_cb, cb_data);
    if (cb_data->query == NULL) {
        err("Failed to submit DNS query: %s", dns_strerror(dns_status(ctx)));
        cb_data->client_free_cb(cb_data->client_cb_data);
        free(cb_data);
        return NULL;
    }

    return cb_data;
}
コード例 #2
0
ファイル: mod_udns.c プロジェクト: temoto/pyudns
/*@null@*/
static PyObject*
Resolver_submit_a4 (Resolver *self, PyObject *args) {
    const char *domain;
    PyObject *cb, *cb_data = Py_None;
    Query *query;
    int flags = 0;

    if (!PyArg_ParseTuple(args, "sO|Oi", &domain, &cb, &cb_data, &flags)) {
        PyErr_SetString(PyExc_TypeError, "Resolver.submit_a4(domain, callback, data=None, flags=0) wrong arguments.");
        return NULL;
    }
    if (!cb || !PyCallable_Check(cb)) {
        PyErr_SetString(PyExc_TypeError, "'callback' is not callable.");
        return NULL;
    }

    query = (Query*)PyObject_CallObject((PyObject*)&QueryType, NULL);
    if (NULL == query) {
        PyErr_SetString(PyExc_MemoryError, "Can't create Query object.");
        return NULL;
    }
    Py_INCREF(self);
    query->resolver = (PyObject*)self;
    Py_INCREF(cb);
    query->callback = cb;
    Py_INCREF(cb_data);
    query->data = cb_data;
    Py_INCREF(query);
    query->q = dns_submit_a4(self->ctx, domain, flags, on_dns_resolve_a4, (void*)query);

    return (PyObject*)query;
}
コード例 #3
0
ファイル: resolv.c プロジェクト: CalixHu/shadowsocksr-libev
struct ResolvQuery *
resolv_query(const char *hostname, void (*client_cb)(struct sockaddr *, void *),
             void (*client_free_cb)(void *), void *client_cb_data,
             uint16_t port)
{
    struct dns_ctx *ctx = (struct dns_ctx *)resolv_io_watcher.data;

    /*
     * Wrap udns's call back in our own
     */
    struct ResolvQuery *cb_data = ss_malloc(sizeof(struct ResolvQuery));
    if (cb_data == NULL) {
        LOGE("Failed to allocate memory for DNS query callback data.");
        return NULL;
    }
    memset(cb_data, 0, sizeof(struct ResolvQuery));

    cb_data->client_cb      = client_cb;
    cb_data->client_free_cb = client_free_cb;
    cb_data->client_cb_data = client_cb_data;
    memset(cb_data->queries, 0, sizeof(cb_data->queries));
    cb_data->response_count = 0;
    cb_data->responses      = NULL;
    cb_data->port           = port;

    /* Submit A and AAAA queries */
    if (resolv_mode != MODE_IPV6_ONLY) {
        cb_data->queries[0] = dns_submit_a4(ctx,
                                            hostname, 0,
                                            dns_query_v4_cb, cb_data);
        if (cb_data->queries[0] == NULL) {
            LOGE("Failed to submit DNS query: %s",
                 dns_strerror(dns_status(ctx)));
        }
    }

    if (resolv_mode != MODE_IPV4_ONLY) {
        cb_data->queries[1] = dns_submit_a6(ctx,
                                            hostname, 0,
                                            dns_query_v6_cb, cb_data);
        if (cb_data->queries[1] == NULL) {
            LOGE("Failed to submit DNS query: %s",
                 dns_strerror(dns_status(ctx)));
        }
    }

    if (all_queries_are_null(cb_data)) {
        if (cb_data->client_free_cb != NULL) {
            cb_data->client_free_cb(cb_data->client_cb_data);
        }
        ss_free(cb_data);
    }

    return cb_data;
}
コード例 #4
0
ファイル: rblcheck.c プロジェクト: asyr625/mini_sip
static int submit(struct ipcheck *ipc) {
  struct in_addr addr;
  if (inet_aton(ipc->name, &addr)) {
    submit_a_queries(ipc, 1, &addr);
    ipc->name = NULL;
  }
  else if (!dns_submit_a4(0, ipc->name, 0, namecb, ipc))
    fprintf(stderr, "%s: unable to submit name query for %s: %s\n",
            progname, ipc->name, dns_strerror(dns_status(0)));
  return 0;
}
コード例 #5
0
ファイル: rblcheck.c プロジェクト: Icarus-xx/reconnoiter
static int submit(struct ipcheck *ipc) {
  struct in_addr addr;
  if (dns_pton(AF_INET, ipc->name, &addr) > 0) {
    submit_a_queries(ipc, 1, &addr);
    ipc->name = NULL;
  }
  else if (!dns_submit_a4(0, ipc->name, 0, namecb, ipc)) {
    error(0, "unable to submit name query for %s: %s\n",
          ipc->name, dns_strerror(dns_status(0)));
    ++failures;
  }
  return 0;
}
コード例 #6
0
ファイル: qcrawler_dns.cpp プロジェクト: Kayven/qcontent
void QCrawlerDNS::async_resolve_host(const std::string &host, void *data)
{
    assert(dns_loop);
    ev_tstamp now = ev_now(dns_loop);

    // check dns cache
    if (dns_cache.find(host) != dns_cache.end()) {
        QCrawlerDNSEntry &entry = dns_cache[host];
        QCrawlerDNSFetchCallback cb = QCrawlerDNS::get_instance()->dns_fetch_callback();

        if (!entry.addr_list.empty()) {
            if (entry.resolve_time + ok_dns_cache_time >= now)  {
                entry.last_pos = (entry.last_pos + 1) % entry.addr_list.size();
                if (cb) {
                    cb(0, &(entry.addr_list[entry.last_pos]), data);
                }

                return;
            }

        } else {
            if (entry.resolve_time + fail_dns_cache_time > now) {
                if (cb) {
                    cb(1, NULL, data);
                }
                return;
            }

        }
    }

    // submit dns task
    if (!dns_submit_a4(dns_ctx, host.c_str(), 0, dns_a4_cb, data)) {
        LOG(WARNING) << "dns sumit a4 eror";
    }
}