Skip to content

Instantly share code, notes, and snippets.

@yasuoka
Created March 24, 2014 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasuoka/4a52204baa542cbe8a01 to your computer and use it in GitHub Desktop.
Save yasuoka/4a52204baa542cbe8a01 to your computer and use it in GitHub Desktop.
/*
* Usage:
* % cc -DDEBUG -o evdns_test2 evdns_test2.c -levent
* % ./evdns_test2
*/
#include <sys/param.h>
#include <sys/time.h>
#include <event2/event.h>
#include <event2/event_struct.h>
#include <event2/dns.h>
#include <stdlib.h>
#ifdef DEBUG
#define DBG(_x) printf _x
#else
#define DBG(_x)
#endif
static void
on_resolved(int res, char t, int c, int ttl, void *addr, void *arg)
{
printf("%s()\n", __func__);
}
static void
on_timeout(int fd, short ev, void *ctx)
{
printf("%s() calling evdns_shutdown(1)\n", __func__);
evdns_shutdown(1);
}
int
main(int argc, char *argv[])
{
struct timeval to = { 20, 500000 };
struct event ev_to;
event_init();
evdns_init();
evdns_clear_nameservers_and_suspend();
evdns_nameserver_ip_add("127.0.0.1");
evdns_resume();
event_set(&ev_to, -1, 0, on_timeout, NULL);
event_add(&ev_to, &to);
/* nameserver doesn't work */
evdns_resolve_ipv4("www.iij.ad.jp", 0, on_resolved, (void *)1);
evdns_resolve_ipv4("www.iij.ad.jp", 0, on_resolved, (void *)1);
event_loop(EVLOOP_ONCE); /* see periodic() */
event_loop(0);
exit(EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment