aboutsummaryrefslogtreecommitdiffstats
path: root/libglouglou/examples
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2012-12-15 05:48:46 +0100
committerLaurent Ghigonis <laurent@p1sec.com>2012-12-15 05:48:46 +0100
commit1c4ab5c1f947a5d4793f582c66ab7f40116e7bec (patch)
treef55bc869bef7a4a0c20bc79051316889168d82c2 /libglouglou/examples
parentcall the user callback even on error but with NULL as name (diff)
downloadglouglou-1c4ab5c1f947a5d4793f582c66ab7f40116e7bec.tar.xz
glouglou-1c4ab5c1f947a5d4793f582c66ab7f40116e7bec.zip
wait 5 seconds maximum, and differentiate error from no answer
Diffstat (limited to 'libglouglou/examples')
-rw-r--r--libglouglou/examples/dnsreverse.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/libglouglou/examples/dnsreverse.c b/libglouglou/examples/dnsreverse.c
index c5ae83b..33b0f75 100644
--- a/libglouglou/examples/dnsreverse.c
+++ b/libglouglou/examples/dnsreverse.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -8,31 +9,43 @@
static void _cb_dns(struct in_addr *, char *, void *);
struct event_base *_ev_base;
+char *_name = NULL;
+int _answer = 0;
int
main(int argc, char *argv[])
{
struct ggnet_dns *ggdns;
struct in_addr ip;
+ struct timeval tv;
if (argc < 2) {
printf("usage: dnsreverse <fqdn>\n");
exit(1);
}
inet_aton(argv[1], &ip);
+ bzero(&tv, sizeof(struct timeval));
+ tv.tv_sec = 5;
_ev_base = event_base_new();
ggdns = ggnet_dns_new(_ev_base);
ggnet_dns_reverse(ggdns, &ip, _cb_dns, NULL);
+ event_base_loopexit(_ev_base, &tv);
event_base_dispatch(_ev_base);
+
+ if (_answer)
+ printf("%x: %s\n", ip.s_addr, _name);
+ else
+ printf("no answer\n");
return 0;
}
static void
_cb_dns(struct in_addr *ip, char *name, void *data)
{
- printf("%x: %s\n", ip->s_addr, name);
+ _name = name;
+ _answer = 1;
event_base_loopexit(_ev_base, NULL);
}