diff options
author | Laurent Ghigonis <laurent@p1sec.com> | 2012-12-15 04:18:51 +0100 |
---|---|---|
committer | Laurent Ghigonis <laurent@p1sec.com> | 2012-12-15 04:18:51 +0100 |
commit | b6f9d1cb1fc279d0f5ab6e2fbc00b7bd0d2861ae (patch) | |
tree | 21b34d206a25b913ea3c63e9e50b211e62851b2e /libglouglou/libggnet_dns.c | |
parent | add (struct ggnet *) in cb_nodename() arguments (diff) | |
download | glouglou-b6f9d1cb1fc279d0f5ab6e2fbc00b7bd0d2861ae.tar.xz glouglou-b6f9d1cb1fc279d0f5ab6e2fbc00b7bd0d2861ae.zip |
add necessary code in libggnet to do resolving of nodes names.
modify libggnet_dns structure to fit with these changes.
Diffstat (limited to 'libglouglou/libggnet_dns.c')
-rw-r--r-- | libglouglou/libggnet_dns.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/libglouglou/libggnet_dns.c b/libglouglou/libggnet_dns.c index 252aba5..be4e19b 100644 --- a/libglouglou/libggnet_dns.c +++ b/libglouglou/libggnet_dns.c @@ -13,15 +13,6 @@ static void _cb_evdns_reverse(int, char, int, int, void *, void *); -struct req_reverse { - LIST_ENTRY(req_reverse) entry; - struct ggnet_dns *ggdns; - struct evdns_request *ereq; - struct in_addr ip; - void (*cb_usr)(struct in_addr *, char *, void *); - void *data; -}; - struct ggnet_dns * ggnet_dns_new(struct event_base *ev_base) { @@ -51,14 +42,14 @@ ggnet_dns_free(struct ggnet_dns *ggdns) free(ggdns); } -int +struct ggnet_dns_req * ggnet_dns_reverse(struct ggnet_dns *ggdns, struct in_addr *ip, void (*cb_usr)(struct in_addr *, char *, void *), void *data) { struct evutil_addrinfo hints; - struct req_reverse *req; + struct ggnet_dns_req *req; struct evdns_request *ereq; memset(&hints, 0, sizeof(hints)); @@ -67,9 +58,9 @@ ggnet_dns_reverse(struct ggnet_dns *ggdns, hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; - req = malloc(sizeof(struct req_reverse)); + req = malloc(sizeof(struct ggnet_dns_req)); if (!req) { - printf("could not allocate req_reverse\n"); + printf("could not allocate ggnet_dns_req\n"); exit(1); } req->ggdns = ggdns; @@ -77,26 +68,33 @@ ggnet_dns_reverse(struct ggnet_dns *ggdns, req->cb_usr = cb_usr; req->data = data; - LIST_INSERT_HEAD(&ggdns->req_reverse_list, req, entry); - ggdns->req_reverse_pending++; + LIST_INSERT_HEAD(&ggdns->req_list, req, entry); + ggdns->req_pending++; ereq = evdns_base_resolve_reverse(ggdns->evdns_base, ip, 0, _cb_evdns_reverse, req); if (ereq == NULL) { printf("libggnet_dns WARNING: dns request for %d returned immediately\n", ip->s_addr); /* remove req from list and free it happened in the callback. */ - return 0; + return NULL; } req->ereq = ereq; - return 1; + return req; +} + +void +ggnet_dns_cancel(struct ggnet_dns *ggdns, struct ggnet_dns_req *req) +{ + evdns_cancel_request(ggdns->evdns_base, req->ereq); + /* remove req from list and free it happened in the callback. */ } static void _cb_evdns_reverse(int result, char type, int count, int ttl, void *addresses, void *arg) { - struct req_reverse *req; + struct ggnet_dns_req *req; req = arg; if (type != DNS_PTR) { @@ -108,6 +106,6 @@ _cb_evdns_reverse(int result, char type, int count, free: LIST_REMOVE(req, entry); - req->ggdns->req_reverse_pending--; + req->ggdns->req_pending--; free(req); } |