How to match the async result? (dns_submit_a4 returns 0 instead of a pointer)

Michael Tokarev mjt at tls.msk.ru
Sat Feb 5 19:59:34 MSK 2011


05.02.2011 16:42, Iñaki Baz Castillo wrote:
[]
> First of all, in my case dns_submit_a4() returns 0:
> 
> ---------------
>   size_t query_ptr;
> 
>   if (query_ptr = dns_submit_a4(dns_context, "google.com", 0,
> dns_res_A_cb, NULL) == 0) {
>     fprintf(stderr, "FATAL: unable to submit query: %s\n",
> dns_strerror(dns_status(0)));
>     return 1;
>   }
>   printf("query_ptr = <%lu>\n", (unsigned long)query_ptr);
> --------------
> 
> Running it I get: "query_ptr = <0>". Shouldn't it be a pointer?

-----------------------------
#include <udns.h>
#include <stdio.h>
static void a4_fn(struct dns_ctx *c, struct dns_rr_a4 *res, void *data) {
  free(res);
}
int main(void) {
  struct dns_query *q;
  struct dns_ctx *c;
  dns_init(NULL, 0);
  c = dns_new(NULL);
  dns_open(c);
  q = dns_submit_a4(c, "google.com", 0, a4_fn, NULL);
  printf("q=%p\n", q);
  return 0;
}
-----------------------------

The above little program prints some non-NULL pointer here,
like `q=0x93c7520'.

> Perhaps should I use the data pointer provided in the dns_submit_a4()
> call as last parameter to match the callback? But that would mean
> before the query I must create a "random" identifier, set it as 'data'
> parameter in dns_submit_a4(), and check 'data' when a callback is
> executed.
> 
> Do I miss something?

I don't understand what you're doing, really.

Yes, that "data" thing is your identifier, or anything you want to
be assotiated with the query.  I don't see why it should be "random" --
you aren't running "random" queries, each query is assotiated with
something, so use that 'something' as your identifier.

Usually you'll have address of some structure as 'data' pointer.
For example, when you write a mailserver, and want to retrieve
name of the connecting client (rDNS), you'll have a "connection"
structure which will be passed as data to the callback.

In short: I don't understand what you're asking.

/mjt


More information about the udns mailing list