originally implemented for 1.4.1-beta, applies and works ok for 1.4.2 as well, being used in production environments.
few libevent users asked when it will be included in distro so im posting the patch here
---------
clean patch against 1.4.2-rc src tree:
sv-fe41s:~/build/levent/d/libevent-1.4.2-rc# patch -p1 < ../libevent-1.4.2-rc_dnsmx.diff
patching file evdns.c
patching file evdns.h
patching file test/regress_dns.c
------------------
regress tests grepped output:
sv-fe41s:~/build/levent/d/libevent-1.4.2-rc# ./test/regress 2>&1 | grep MX
MX DNS resolve: type: 4, count: 4, ttl: 1745: test_domain=aol.com,rr_count=4, first rr: pri=15,mxhost=mailin-02.mx.aol.com OK
sv-fe41s:~/build/levent/d/libevent-1.4.2-rc#
-------------------
howto use it:
..
...
evdns_resolve_mx(domain,DNS_QUERY_NO_SEARCH,process_mx2,(void *)domain);
...
...
/* your callback: */
static void process_mx2 (int result, char type, int count, int ttl, void *addresses, void *arg)
{
struct mx_rr *records = (struct mx_rr *)addresses;
int i = 0;
for (i = 0; i < count; i++) {
printf("%d %d %s\n", i, records[i].pri, records[i].host);
}
}
/* struct mx_rr is defined in evdns.h: */
struct mx_rr {
uint16_t pri;
char host[255];
};
diff output against 1.4.2-rc src tree
Logged In: YES
user_id=499
Originator: NO
I'd be interested in doing this in the context of a more general approach that allows arbitrary DNS queries to be generated. I worry that if we do a MX-query function, we'll soon have queries for all the other possible query types, and then feel stupid that we didn't provide functions for queries with *multiple* questions, and so on.
I should be more constructive than that:
There are lots of DNS record types. We should be able to query arbitrary records, not just have one function for every kind of record we can think of.