static void dns_gethostbyaddr(void) { struct in_addr in; in.s_addr = htonl(0x7f000001ul); /* 127.0.0.1 */ dns_ok = 0; evdns_resolve_reverse(&in, 0, dns_gethostbyname_cb, NULL); event_dispatch(); tt_int_op(dns_ok, ==, DNS_PTR); test_ok = dns_ok; end: ; }
void analyze_country_enter(const struct addr *addr, const struct addr *dst) { struct keycount tmpkey, *key; struct country_state *state = calloc(1, sizeof(struct country_state)); if (state == NULL) { syslog(LOG_ERR, "%s: failed to calloc state", __func__); exit(EXIT_FAILURE); } state->src = *addr; state->dst = *dst; /* * Check if this IP returned a resolver error in the last hour. */ tmpkey.key = &addr->addr_ip; tmpkey.keylen = sizeof(addr->addr_ip); if ((key = SPLAY_FIND(kctree, &country_cache, &tmpkey)) != NULL) { if (count_get_minute(key->count) || count_get_hour(key->count)) { state->result_from_cache = 1; analyze_country_enter_cb(DNS_ERR_NOTEXIST, DNS_PTR, 0, 0, NULL, state); return; } } if (!checkpoint_doreplay) { struct in_addr in; in.s_addr = addr->addr_ip; evdns_resolve_reverse(&in, 0, analyze_country_enter_cb, state); } else { /* * If we are replaying a checkpoint, we do not want to do * async calls. */ struct hostent *hp = gethostbyaddr( (const char *)&addr->addr_ip, IP_ADDR_LEN, AF_INET); if (hp == NULL) { analyze_country_enter_cb(DNS_ERR_NOTEXIST, DNS_PTR, 0, 0, NULL, state); } else { analyze_country_enter_cb(DNS_ERR_NONE, DNS_PTR, 1, 1200 /* ttl */, (void *)&hp->h_name, state); } } }
static void dns_gethostbyaddr(void) { struct in_addr in; in.s_addr = htonl(0x7f000001ul); /* 127.0.0.1 */ fprintf(stdout, "Simple reverse DNS resolve: "); dns_ok = 0; evdns_resolve_reverse(&in, 0, dns_gethostbyname_cb, NULL); event_dispatch(); if (dns_ok == DNS_PTR) { fprintf(stdout, "OK\n"); } else { fprintf(stdout, "FAILED\n"); exit(1); } }
static void dns_server(void) { int sock; struct sockaddr_in my_addr; struct evdns_server_port *port; struct in_addr resolve_addr; dns_ok = 1; fprintf(stdout, "DNS server support: "); /* Add ourself as the only nameserver, and make sure we really are * the only nameserver. */ evdns_nameserver_ip_add("127.0.0.1:35353"); if (evdns_count_nameservers() != 1) { fprintf(stdout, "Couldn't set up.\n"); exit(1); } /* Now configure a nameserver port. */ sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock == -1) { perror("socket"); exit(1); } #ifdef WIN32 { u_long nonblocking = 1; ioctlsocket(sock, FIONBIO, &nonblocking); } #else fcntl(sock, F_SETFL, O_NONBLOCK); #endif memset(&my_addr, 0, sizeof(my_addr)); my_addr.sin_family = AF_INET; my_addr.sin_port = htons(35353); my_addr.sin_addr.s_addr = htonl(0x7f000001UL); if (bind(sock, (struct sockaddr*)&my_addr, sizeof(my_addr)) < 0) { perror("bind"); exit (1); } port = evdns_add_server_port(sock, 0, dns_server_request_cb, NULL); /* Send two queries. */ evdns_resolve_ipv4("zz.example.com", DNS_QUERY_NO_SEARCH, dns_server_gethostbyname_cb, NULL); evdns_resolve_ipv6("zz.example.com", DNS_QUERY_NO_SEARCH, dns_server_gethostbyname_cb, NULL); resolve_addr.s_addr = htonl(0xc0a80b0bUL); /* 192.168.11.11 */ evdns_resolve_reverse(&resolve_addr, 0, dns_server_gethostbyname_cb, NULL); event_dispatch(); if (dns_ok) { fprintf(stdout, "OK\n"); } else { fprintf(stdout, "FAILED\n"); exit(1); } evdns_close_server_port(port); evdns_shutdown(0); /* remove ourself as nameserver. */ #ifdef WIN32 closesocket(sock); #else close(sock); #endif }