libraries/EtherShield/EtherShield.cpp
// Perform all processing to resolve a hostname to IP address.
// Returns 1 for successful Name resolution, 0 otherwise
Perform all processing to resolve a hostname to IP address.
Returns 1 for successful Name resolution, 0 otherwise
Perform all processing to resolve a hostname to IP address . Returns 1 for successful Name resolution 0 otherwise
uint8_t EtherShield::resolveHostname(uint8_t *buf, uint16_t buffer_size, uint8_t *hostname ) {
  uint16_t dat_p;
  int plen = 0;
  long lastDnsRequest = millis();
  uint8_t dns_state = DNS_STATE_INIT;
  boolean gotAddress = false;
  uint8_t dnsTries = 3;	
  while( !gotAddress ) {
    plen = enc28j60PacketReceive(buffer_size, buf);
    dat_p=packetloop_icmp_tcp(buf,plen);
    if (dat_p == 0) {
      if (client_waiting_gw() ) {
        continue;
      }
      if (dns_state==DNS_STATE_INIT) {
        dns_state=DNS_STATE_REQUESTED;
        lastDnsRequest = millis();
        dnslkup_request(buf,hostname);
        continue;
      }
      if (dns_state!=DNS_STATE_ANSWER){
        if (millis() > (lastDnsRequest + 60000L) ){
	  if( --dnsTries <= 0 ) 
	    return 0;		
          dns_state=DNS_STATE_INIT;
          lastDnsRequest = millis();
        }
        continue;
      }
    } 
    else {
      if (dns_state==DNS_STATE_REQUESTED && udp_client_check_for_dns_answer( buf, plen ) ){
        dns_state=DNS_STATE_ANSWER;
        client_tcp_set_serverip(dnslkup_getip());
	gotAddress = true;
      }
    }
  }
  return 1;
}
uint8_t EtherShield :: resolveHostname ( uint8_t * buf , uint16_t buffer_size , uint8_t * hostname ) { uint16_t dat_p ; int plen = 0 ; long lastDnsRequest = millis ( ) ; uint8_t dns_state = DNS_STATE_INIT ; boolean gotAddress = false ; uint8_t dnsTries = 3 ; while ( ! gotAddress ) { plen = enc28j60PacketReceive ( buffer_size , buf ) ; dat_p = packetloop_icmp_tcp ( buf , plen ) ; if ( dat_p == 0 ) { if ( client_waiting_gw ( ) ) { continue ; } if ( dns_state == DNS_STATE_INIT ) { dns_state = DNS_STATE_REQUESTED ; lastDnsRequest = millis ( ) ; dnslkup_request ( buf , hostname ) ; continue ; } if ( dns_state != DNS_STATE_ANSWER ) { if ( millis ( ) > ( lastDnsRequest + 60000L ) ) { if ( -- dnsTries <= 0 ) return 0 ; dns_state = DNS_STATE_INIT ; lastDnsRequest = millis ( ) ; } continue ; } } else { if ( dns_state == DNS_STATE_REQUESTED && udp_client_check_for_dns_answer ( buf , plen ) ) { dns_state = DNS_STATE_ANSWER ; client_tcp_set_serverip ( dnslkup_getip ( ) ) ; gotAddress = true ; } } } return 1 ; }
Perform all processing to resolve a hostname to IP address.
Perform all processing to resolve a hostname to IP address .
// After 10 attempts fail gracefully so other action can be carried out // handle ping and wait for a tcp packet // We have a packet // Check if IP data // No ARP received for gateway // It has IP data // retry every minute if dns-lookup failed: // Failed to allocate address // don't try to use client before // we have a result of dns-lookup //client_set_wwwip(dnslkup_getip());