void dns_handle_request(dns_request_t *m) { dns_request_t *ptr = NULL; /* request may be a new query or a answer from the upstream server */ ptr = dns_list_find_by_id( dns_request_list, m ); if( ptr != NULL ){ debug("Found query in list\n"); /* message may be a response */ if( m->message.header.flags.f.question == 1 ){ dns_write_packet( dns_sock, ptr->src_addr, ptr->src_port, m ); debug("Replying with answer from %s\n", inet_ntoa( m->src_addr )); if( m->message.header.flags.f.rcode == 0 && /* modified by CMC 2002/12/6 */ (ptr->message.question[0].type == A || ptr->message.question[0].type == PTR) ){ debug("Cache append: %s ----> %s\n", m->cname, m->ip ); cache_name_append( m->cname, m->ip ); } dns_request_list = dns_list_remove( dns_request_list, ptr ); }else{ ptr->duplicate_queries++; /* added by CMC 8/4/2001 */ debug("Duplicate query(%d)\n", ptr->duplicate_queries); forward_dns_query( ptr, m ); /* added by CMC 8/4/2001 */ } }else{ dns_handle_new_query( m ); } }
void dns_handle_request(dns_request_t *m) { dns_request_t *ptr = NULL; /* request may be a new query or a answer from the upstream server */ ptr = dns_list_find_by_id( dns_request_list, m ); if( ptr != NULL ){ debug("Found query in list\n"); /* message may be a response */ if( m->message.header.flags.f.question == 1 ){ if( m->message.header.flags.f.rcode == 0 ){ // lookup was succesful dns_write_packet( dns_sock, ptr->src_addr, ptr->src_port, m ); debug("Replying with answer from %s\n", inet_ntoa( m->src_addr )); dns_request_list = dns_list_remove( dns_request_list, ptr ); debug("Cache append: %s ----> %s\n", m->cname, m->ip ); cache_name_append( m->cname, m->ip ); } /*if( m->message.header.flags.f.question == 1 ){ dns_write_packet( dns_sock, ptr->src_addr, ptr->src_port, m ); debug("Replying with answer from %s\n", inet_ntoa( m->src_addr )); dns_request_list = dns_list_remove( dns_request_list, ptr ); if( m->message.header.flags.f.rcode == 0 ){ // lookup was succesful debug("Cache append: %s ----> %s\n", m->cname, m->ip ); cache_name_append( m->cname, m->ip ); }*/ }else{ debug("Duplicate query\n"); } }else{ dns_handle_new_query( m ); } }