On date Thursday 2008-06-12 13:40:25 +0300, Pekka Pessi wrote: > 2008/6/10 Stefano Sabatini <[EMAIL PROTECTED]>: > > I'm trying to understand how the sresolv "simple" interface works. > > "Simple" interface is intended for cases where your main loop is > running with su_root_t. > You can try to use "blocking" interface, see utils/sip-dig.c for an example.
Thank you Pekka, here it is a complete example of use of the blocking interface. somehow extrapolated by sip-dig.c. I'm posting it for the archive. -----------------------------------8<----------------------------------------- #include <sofia-sip/sresolv.h> #include <sofia-sip/su_log.h> #include "sofia-sip/url.h" #include <stdlib.h> #include <stdio.h> int main(int argc, char** argv) { url_t *url; if (argc <= 1) { fprintf(stderr, "Missing the address to resolve"); exit(1); } const char* url_str = argv[1]; /* parse the string and fill accordingly all the fields of the url struct */ url = url_hdup(NULL, (void *)url_str); if (url && url->url_type == url_unknown) url_sanitize(url); /* Initialize Sofia-SIP library and create event loop */ su_init (); su_log_set_level(NULL, 9); /* root = su_root_create(NULL); */ /* at first I need to create the DNS resolver object */ /* blocking interface */ /* instantiate the resolver */ sres_resolver_t* sres = sres_resolver_new(NULL); if(!sres) { fprintf(stderr, "Impossible to instantiate a resolver, exiting"); exit(1); } /* then I need the sres_record_t struct where to put the request for the query */ sres_record_t** answers= NULL; const char *resolvaddr = NULL; if (host_is_ip_address(url->url_host)) { /* it's already resolved, no need to ask the DNS server */ printf("%s\n", url->url_host); exit(0); } if (sres_blocking_query(sres, sres_type_a, url->url_host, 0, &answers) < 0) { fprintf(stderr, "Impossible to resolve address: %s", url); exit(1); } int i; char addr[64]; for (i = 0; answers[i]; i++) { /* sofia redefines the inet_ntop if it isn't already defined in the system */ su_inet_ntop(AF_INET, &answers[i]->sr_a->a_addr, addr, sizeof addr); printf("%s\n", addr); } sres_free_answers(sres, answers); sres_resolver_unref(sres); exit(0); } -----------------------------------8<----------------------------------------- Regards. ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Sofia-sip-devel mailing list Sofia-sip-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel