Exemple #1
0
void process_dns_questions(int fd, dns_message_iterator_t* iter )
{
  dns_name_t name;
  dns_question_t question;
  dns_message_iterator_t response;
  int a = 0;
  int question_processed;
  u32 myip = htonl(my_ip_addr);

  memset( &response, 0, sizeof(dns_message_iterator_t) );
    
  for ( a = 0; a < htons(iter->header->question_count); ++a )
  {
    dns_get_next_question( iter, &question, &name );
    question_processed = 0;
    switch ( question.question_type ){
      case RR_TYPE_PTR:
        if ( available_services != NULL ){
          // Check if its a query for all available services
          if ( dns_compare_name_to_string( &name, SERVICE_QUERY_NAME ) ){
            int b = 0;
            printf("Recv a SERVICE QUERY request.\r\n");
            dns_create_message( &response, 512 );
						dns_write_header(&response, iter->header->id, 0x8400, 0, available_service_count, 0 );          
            for ( b = 0; b < available_service_count; ++b ){
              dns_write_record( &response, SERVICE_QUERY_NAME, RR_CLASS_IN, RR_TYPE_PTR, 300, (u8*) available_services[b].service_name );
            }
            mdns_send_message(fd, &response );
            dns_free_message( &response );
            question_processed = 1;
          }
          // else check if its one of our records
          else {
            int b = 0;
            for ( b = 0; b < available_service_count; ++b ){
              if ( dns_compare_name_to_string( &name, available_services[b].service_name )){
                // Send the PTR, TXT, SRV and A records
                printf("Recv a SERVICE Detail request.\r\n");
                dns_create_message( &response, 512 );
                dns_write_header( &response, iter->header->id, 0x8400, 0, 4, 0 );
                dns_write_record( &response, available_services[b].service_name, RR_CLASS_IN, RR_TYPE_PTR, 300, (u8*) available_services[b].instance_name );
                dns_write_record( &response, available_services[b].instance_name, RR_CACHE_FLUSH|RR_CLASS_IN, RR_TYPE_TXT, 300, (u8*) available_services->txt_att );
                dns_write_record( &response, available_services[b].instance_name, RR_CACHE_FLUSH|RR_CLASS_IN, RR_TYPE_SRV, 300, (u8*) &available_services[b]);
                dns_write_record( &response, available_services[b].hostname, RR_CACHE_FLUSH|RR_CLASS_IN, RR_TYPE_A, 300, (u8*) &myip);
                mdns_send_message(fd, &response );
                dns_free_message( &response );
                question_processed = 1;
              }
            }
          }
        }
        break;
      }
      if (!question_processed ){
        printf("Recv a mDNS request.\r\n");
        mdns_process_query(fd, &name, &question, iter);
      }
    }
}
static void mdns_process_query(int fd, dns_name_t* name, 
                               dns_question_t* question, dns_message_iterator_t* source )
{
  dns_message_iterator_t response;
  IPStatusTypedef para;
  uint32_t myip;
  int b = 0;
  
  memset( &response, 0, sizeof(dns_message_iterator_t) );
  
  switch ( question->question_type )
  {
  case RR_QTYPE_ANY:
  case RR_TYPE_A:
    for ( b = 0; b < available_service_count; ++b ){
      if ( dns_compare_name_to_string( name, available_services[b].hostname ) ){				

        micoWlanGetIPStatus(&para, available_services[b].interface);
        myip = htonl(inet_addr(para.ip));
        if( myip == 0 || myip == 0xFFFFFFFF) continue;

        if(dns_create_message( &response, 256 )){
          dns_write_header( &response, source->header->id, 0x8400, 0, 1, 0 );
          dns_write_record( &response, available_services[b].hostname, RR_CLASS_IN | RR_CACHE_FLUSH, RR_TYPE_A, available_services[b].ttl, (uint8_t *)&myip);
          mdns_send_message(fd, &response );
          dns_free_message( &response );
          return;
        }
      }
    }    
  default:
   break;;
  }
}
Exemple #3
0
static void mdns_process_query(int fd, dns_name_t* name, 
                               dns_question_t* question, dns_message_iterator_t* source )
{
  dns_message_iterator_t response;
  IPStatusTypedef para;
  uint32_t myip;
  
  micoWlanGetIPStatus(&para, _interface);
  myip = htonl(inet_addr(para.ip));
  
  memset( &response, 0, sizeof(dns_message_iterator_t) );
  
  switch ( question->question_type )
  {
  case RR_QTYPE_ANY:
  case RR_TYPE_A:
    if ( dns_compare_name_to_string( name, available_services->hostname, __FUNCTION__, __LINE__) ){				
      _debug_out("UDP multicast test: Recv RR_TYPE_A.\r\n");
      if(dns_create_message( &response, 256 )){
        dns_write_header( &response, source->header->id, 0x8400, 0, 1, 0 );
        dns_write_record( &response, available_services->hostname, RR_CLASS_IN | RR_CACHE_FLUSH, RR_TYPE_A, 300, (uint8_t *)&myip);
        mdns_send_message(fd, &response );
        dns_free_message( &response );
        return;
      }
    }    
  default:
    _debug_out("UDP multicast test: Request not support type: %d.---------------------\r\n", question->question_type);
  }
}
Exemple #4
0
static void mdns_process_query(int fd, dns_name_t* name, 
                               dns_question_t* question, dns_message_iterator_t* source )
{
  dns_message_iterator_t response;
  u32 myip = htonl(my_ip_addr);

  memset( &response, 0, sizeof(dns_message_iterator_t) );

  switch ( question->question_type )
  {
    case RR_QTYPE_ANY:
    case RR_TYPE_A:
    if ( dns_compare_name_to_string( name, available_services->hostname ) ){				
      dns_create_message( &response, 256 );
      dns_write_header( &response, source->header->id, 0x8400, 0, 1, 0 );
      dns_write_record( &response, available_services->hostname, RR_CLASS_IN | RR_CACHE_FLUSH, RR_TYPE_A, 300, (u8*)&myip);
      mdns_send_message(fd, &response );
      dns_free_message( &response );
    }
    break;
  }
}
void process_dns_questions(int fd, dns_message_iterator_t* iter )
{
  dns_name_t name;
  dns_question_t question;
  dns_message_iterator_t response;
  IPStatusTypedef para;
  int a = 0;
  int question_processed;
  uint32_t myip;
  
  memset( &response, 0, sizeof(dns_message_iterator_t) );
  
  for ( a = 0; a < htons(iter->header->question_count); ++a )
  {
    if (iter->iter > iter->end)
      break;
    if(dns_get_next_question( iter, &question, &name )==0)
      break;
    question_processed = 0;
    switch ( question.question_type ){
    case RR_TYPE_PTR:
      if ( available_services != NULL ){
        // Check if its a query for all available services  
        if ( dns_compare_name_to_string( &name, SERVICE_QUERY_NAME ) ){
          int b = 0;
          if(dns_create_message( &response, 512 )) {
            dns_write_header(&response, iter->header->id, 0x8400, 0, available_service_count, 0 );          
            for ( b = 0; b < available_service_count; ++b ){
              dns_write_record( &response, SERVICE_QUERY_NAME, RR_CLASS_IN, RR_TYPE_PTR, 1500, (uint8_t*) available_services[b].service_name );
            }
            mdns_send_message(fd, &response );
            dns_free_message( &response );
            question_processed = 1;
          }
        }
        // else check if its one of our records
        else {
          int b = 0;
          for ( b = 0; b < available_service_count; ++b ){
            //printf("UDP multicast test: Recv a SERVICE Detail request: %s.\r\n", name);
            if ( dns_compare_name_to_string( &name, available_services[b].service_name )){
              
              if( available_services[b].state != RECORD_NORMAL )
                continue;

              micoWlanGetIPStatus(&para, available_services[b].interface);
              myip = htonl(inet_addr(para.ip));
              if( myip == 0 || myip == 0xFFFFFFFF) continue;
              
              // Send the PTR, TXT, SRV and A records
              if(dns_create_message( &response, 512 )){
                dns_write_header( &response, iter->header->id, 0x8400, 0, 4, 0 );
                //dns_write_record( &response, MFi_SERVICE_QUERY_NAME, RR_CLASS_IN, RR_TYPE_PTR, 1500, (u8*) available_services[b].service_name );
                dns_write_record( &response, available_services[b].service_name, RR_CLASS_IN, RR_TYPE_PTR, available_services[b].ttl, (uint8_t*) available_services[b].instance_name );
                dns_write_record( &response, available_services[b].instance_name, RR_CACHE_FLUSH|RR_CLASS_IN, RR_TYPE_TXT, available_services[b].ttl, (uint8_t*) available_services[b].txt_att );
                dns_write_record( &response, available_services[b].instance_name, RR_CACHE_FLUSH|RR_CLASS_IN, RR_TYPE_SRV, available_services[b].ttl, (uint8_t*) &available_services[b]);
                dns_write_record( &response, available_services[b].hostname, RR_CACHE_FLUSH|RR_CLASS_IN, RR_TYPE_A, available_services[b].ttl, (uint8_t*) &myip);
                mdns_send_message(fd, &response );
                dns_free_message( &response );
                question_processed = 1;
              }
            }
          }
        }
      }
      break;
    }
    if (!question_processed ){
      mdns_process_query(fd, &name, &question, iter);
    }
  }
}
Exemple #6
0
void process_dns_questions(int fd, dns_message_iterator_t* iter )
{
  dns_name_t name;
  dns_question_t question;
  dns_message_iterator_t response;
  net_para_st para;
  int a = 0;
  int question_processed;
  u32 myip;
  
  getNetPara(&para, _interface);
  myip = htonl(inet_addr(para.ip));
  if(myip == 0) {
    _debug_out("UDP multicast test: IP error.\r\n");
    return;
  }
  
  memset( &response, 0, sizeof(dns_message_iterator_t) );
  
  for ( a = 0; a < htons(iter->header->question_count); ++a )
  {
    if (iter->iter > iter->end)
      break;
    if(dns_get_next_question( iter, &question, &name )==0)
      break;
    question_processed = 0;
    switch ( question.question_type ){
    case RR_TYPE_PTR:
      if ( available_services != NULL ){
        // Check if its a query for all available services  
        if ( dns_compare_name_to_string( &name, MFi_SERVICE_QUERY_NAME, __FUNCTION__, __LINE__ ) ){
          int b = 0;
          _debug_out("UDP multicast test: Recv a SERVICE QUERY request.\r\n");
          if(dns_create_message( &response, 512 )) {
            dns_write_header(&response, iter->header->id, 0x8400, 0, available_service_count, 0 );          
            for ( b = 0; b < available_service_count; ++b ){
              dns_write_record( &response, MFi_SERVICE_QUERY_NAME, RR_CLASS_IN, RR_TYPE_PTR, 1500, (u8*) available_services[b].service_name );
            }
            mdns_send_message(fd, &response );
            dns_free_message( &response );
            question_processed = 1;
          }
        }
        // else check if its one of our records
        else {
          int b = 0;
          for ( b = 0; b < available_service_count; ++b ){
            //printf("UDP multicast test: Recv a SERVICE Detail request: %s.\r\n", name);
            if ( dns_compare_name_to_string( &name, available_services[b].service_name, __FUNCTION__, __LINE__ )){
              // Send the PTR, TXT, SRV and A records
              if(dns_create_message( &response, 512 )){
                dns_write_header( &response, iter->header->id, 0x8400, 0, 4, 0 );
                //dns_write_record( &response, MFi_SERVICE_QUERY_NAME, RR_CLASS_IN, RR_TYPE_PTR, 1500, (u8*) available_services[b].service_name );
                dns_write_record( &response, available_services[b].service_name, RR_CACHE_FLUSH|RR_CLASS_IN, RR_TYPE_PTR, 1500, (u8*) available_services[b].instance_name );
                dns_write_record( &response, available_services[b].instance_name, RR_CACHE_FLUSH|RR_CLASS_IN, RR_TYPE_TXT, 1500, (u8*) available_services[b].txt_att );
                dns_write_record( &response, available_services[b].instance_name, RR_CACHE_FLUSH|RR_CLASS_IN, RR_TYPE_SRV, 1500, (u8*) &available_services[b]);
                dns_write_record( &response, available_services[b].hostname, RR_CACHE_FLUSH|RR_CLASS_IN, RR_TYPE_A, 1500, (u8*) &myip);
                mdns_send_message(fd, &response );
                dns_free_message( &response );
                question_processed = 1;
              }
              else{
                _debug_out("UDP multicast test: Send error.\r\n");
              }
            }
          }
        }
      }
      break;
    }
    if (!question_processed ){
      _debug_out("UDP multicast test: Recv a mDNS request.\r\n");
      mdns_process_query(fd, &name, &question, iter);
    }
  }
}