int firedns_getname4(const struct in_addr *const ip) { /* build, add and send PTR query; retrieve result with firedns_getresult() */ char query[512]; struct s_header h; struct s_connection *s; unsigned char *c; int l; firedns_init(); c = (unsigned char *)&ip->s_addr; sprintf(query,"%d.%d.%d.%d.in-addr.arpa",c[3],c[2],c[1],c[0]); l = firedns_build_query_payload(query,FDNS_QRY_PTR,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class_ = 1; s->type = FDNS_QRY_PTR; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; }
int main() { int i; double libc, fire; struct firedns_state state, *s = &state; firedns_init(s); firedns_add_servers_from_resolv_conf(s); printf("Testing %d firedns_resolveip4list(\"%s\"):\n",TESTS,TEST_HOST); start_time(); for (i = 0; i < TESTS; i++) firedns_resolveip4list(s, TEST_HOST); fire = end_time(); printf("Testing %d gethostbyname(\"%s\"):\n",TESTS,TEST_HOST); start_time(); for (i = 0; i < TESTS; i++) gethostbyname(TEST_HOST); libc = end_time(); if (libc > fire) printf("Speedup: %d%%\n",(int) (((libc - fire) / libc) * 100.0)); else printf("Slowdown: %d%%\n",(int) (((fire - libc) / libc) * 100.0)); return 0; }
int firedns_getname6(const struct in6_addr *const ip) { char query[512]; struct s_header h; struct s_connection *s; int l; firedns_init(); sprintf(query,"%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.ip6.int", ip->s6_addr[15] & 0x0f, (ip->s6_addr[15] & 0xf0) >> 4, ip->s6_addr[14] & 0x0f, (ip->s6_addr[14] & 0xf0) >> 4, ip->s6_addr[13] & 0x0f, (ip->s6_addr[13] & 0xf0) >> 4, ip->s6_addr[12] & 0x0f, (ip->s6_addr[12] & 0xf0) >> 4, ip->s6_addr[11] & 0x0f, (ip->s6_addr[11] & 0xf0) >> 4, ip->s6_addr[10] & 0x0f, (ip->s6_addr[10] & 0xf0) >> 4, ip->s6_addr[9] & 0x0f, (ip->s6_addr[9] & 0xf0) >> 4, ip->s6_addr[8] & 0x0f, (ip->s6_addr[8] & 0xf0) >> 4, ip->s6_addr[7] & 0x0f, (ip->s6_addr[7] & 0xf0) >> 4, ip->s6_addr[6] & 0x0f, (ip->s6_addr[6] & 0xf0) >> 4, ip->s6_addr[5] & 0x0f, (ip->s6_addr[5] & 0xf0) >> 4, ip->s6_addr[4] & 0x0f, (ip->s6_addr[4] & 0xf0) >> 4, ip->s6_addr[3] & 0x0f, (ip->s6_addr[3] & 0xf0) >> 4, ip->s6_addr[2] & 0x0f, (ip->s6_addr[2] & 0xf0) >> 4, ip->s6_addr[1] & 0x0f, (ip->s6_addr[1] & 0xf0) >> 4, ip->s6_addr[0] & 0x0f, (ip->s6_addr[0] & 0xf0) >> 4 ); l = firedns_build_query_payload(query,FDNS_QRY_PTR,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = (struct s_connection *) firedns_add_query(&h); if (s == NULL) return -1; s->class_ = 1; s->type = FDNS_QRY_PTR; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; }
int main() { firedns_state state, *s = &state; firedns_init(s); firedns_add_servers_from_resolv_conf(s); do_firedns_aton4(s, "1.2.3.4"); do_firedns_aton4(s, "101.102.103.104"); do_firedns_aton4(s, "bah"); do_firedns_aton4(s, "1.2.3.400"); do_firedns_aton4(s, "206.152.182.152"); do_firedns_aton4(s, "206.152.182.152)"); do_firedns_aton4(s, "ack started..."); do_firedns_aton6(s, "::"); do_firedns_aton6(s, "3ffe:b80:346:1:204:5aff:fece:7852"); do_firedns_aton6(s, "fe80::204:5aff:fece:7852"); do_firedns_aton6(s, "bah"); do_firedns_getip4(s, "celery.n.ml.org"); do_firedns_getip4(s, "pp.info.uni-karlsruhe.de"); do_firedns_getip4(s, "ftp.kernel.org"); do_firedns_getip4(s, "pokr.com"); do_firedns_getip6(s, "ftp.stealth.net"); do_firedns_getip6(s, "www.ipv6.org"); do_firedns_getip6(s, "z.ip6.int"); do_firedns_gettxt(s, "2668.8086.pci.id.ucw.cz"); do_firedns_gettxt(s, "2.0.0.127.outputs.orbz.org"); do_firedns_gettxt(s, "2.0.0.127.bl.spamcop.net"); do_firedns_gettxt(s, "2.0.0.127.relays.ordb.org"); do_firedns_getmx(s, "spamcop.net"); do_firedns_getmx(s, "penguinhosting.net"); do_firedns_getmx(s, "taconic.net"); do_firedns_getmx(s, "microsoft.com"); do_firedns_getmx(s, "mail.ru"); do_firedns_getmx(s, "cool.dk"); do_firedns_getname4(s, "8.8.8.8"); do_firedns_getname4(s, "208.171.237.190"); do_firedns_getname4(s,"64.28.67.150"); do_firedns_getname4(s, "64.90.162.91"); do_firedns_getname6(s, "2a00:1450:400c:c05::1b"); do_firedns_getname6(s, "2001:660:1180:1:192:134:0:49"); do_firedns_getname6(s, "2001:6b0:e:2018::172"); do_firedns_dnsbl_lookup(s, "127.0.0.2","list.dsbl.org"); return 0; }
int firedns_getcname(const char *const name) { struct s_header h; struct s_connection *s; int l; firedns_init(); l = firedns_build_query_payload(name,FDNS_QRY_CNAME,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = (struct s_connection *) firedns_add_query(&h); if (s == NULL) return -1; s->class_ = 1; s->type = FDNS_QRY_CNAME; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; }
int firedns_getmx(const char *const name) { /* build, add and send MX query; retrieve result with firedns_getresult() */ struct s_header h; struct s_connection *s; int l; firedns_init(); l = firedns_build_query_payload(name,FDNS_QRY_MX,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class_ = 1; s->type = FDNS_QRY_MX; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; }
int main(int argc, char **argv) { struct in_addr *result; firedns_state dns, *d = &dns; char ntoabuf[256]; if (argc != 2) { dprintf(2,"usage: %s <hostname>\n",argv[0]); return 2; } firedns_init(d); firedns_add_server(d, "8.8.8.8"); result = firedns_resolveip4(d, argv[1]); if (result) { printf("%s\n",firedns_ntoa4(result, ntoabuf)); return 0; } return 1; }
/* Load configuration from filename, via flex/bison parser */ void config_load(const char *filename) { config_init(); config_setup(); /* Setup/clear current configuration */ log_printf("CONFIG -> Loading %s", filename); if ((yyin = fopen(filename, "r")) == NULL) { log_printf("CONFIG -> Error opening %s: %s", filename, strerror(errno)); exit(EXIT_FAILURE); } yyparse(); fclose(yyin); scan_init(); /* Initialize the scanners once we have the configuration */ stats_init(); /* Initialize stats (UPTIME) */ firedns_init(); /* Initialize adns */ }
static void init_firedns(void) { firedns_init(&fire); firedns_add_server(&fire, "8.8.4.4"); firedns_add_server(&fire, "8.8.8.8"); }