我其实也不是很明白adns的使用,自己找了很久也没有一个好用例子,今天自己人品爆发能解析dns了,贴出来帮别人,如果你
知道adns更详细的使用别忘了告诉我。
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include "./adns.h"
int main(int argc, char *argv[]) {
adns_state adns;
adns_query query;
adns_answer *answer;
char* cname = NULL;
//adns_init(&adns, adns_if_noenv, 0);
adns_initflags flags = adns_initflags(adns_if_nosigpipe
| adns_if_noerrprint);
adns_init(&adns, flags, NULL);
adns_submit(adns, argv[1], adns_r_a,
(adns_queryflags) (adns_qf_quoteok_cname | adns_qf_cname_loose),
NULL, &query);
adns_wait(adns, &query, &answer, NULL);
printf("%s\n", argv[1]);
printf("%s\n", answer->status == adns_s_ok ? inet_ntoa(*answer->rrs.inaddr)
: "dunno");
adns_finish(adns);
return 0;
}
知道adns更详细的使用别忘了告诉我。
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include "./adns.h"
int main(int argc, char *argv[]) {
adns_state adns;
adns_query query;
adns_answer *answer;
char* cname = NULL;
//adns_init(&adns, adns_if_noenv, 0);
adns_initflags flags = adns_initflags(adns_if_nosigpipe
| adns_if_noerrprint);
adns_init(&adns, flags, NULL);
adns_submit(adns, argv[1], adns_r_a,
(adns_queryflags) (adns_qf_quoteok_cname | adns_qf_cname_loose),
NULL, &query);
adns_wait(adns, &query, &answer, NULL);
printf("%s\n", argv[1]);
printf("%s\n", answer->status == adns_s_ok ? inet_ntoa(*answer->rrs.inaddr)
: "dunno");
adns_finish(adns);
return 0;
}