libraries/EtherShield/EtherShield.cpp
// Perform all processing to get an IP address plus other addresses returned, e.g. gw, dns, dhcp server.
// Returns 1 for successful IP address allocation, 0 otherwise
Perform all processing to get an IP address plus other addresses returned, e.g. gw, dns, dhcp server.
Returns 1 for successful IP address allocation, 0 otherwise
Perform all processing to get an IP address plus other addresses returned e . g . gw dns dhcp server . Returns 1 for successful IP address allocation 0 otherwise
uint8_t EtherShield::allocateIPAddress(uint8_t *buf, uint16_t buffer_size, uint8_t *mymac, uint16_t myport, uint8_t *myip, uint8_t *mynetmask, uint8_t *gwip, uint8_t *dnsip, uint8_t *dhcpsvrip ) {
  uint16_t dat_p;
  int plen = 0;
  long lastDhcpRequest = millis();
  uint8_t dhcpState = 0;
  boolean gotIp = false;
  uint8_t dhcpTries = 10;	
  dhcp_start( buf, mymac, myip, mynetmask,gwip, dnsip, dhcpsvrip );
  while( !gotIp ) {
    plen = enc28j60PacketReceive(buffer_size, buf);
    dat_p=packetloop_icmp_tcp(buf,plen);
    if(dat_p==0) {
      int retstat = check_for_dhcp_answer( buf, plen);
      dhcpState = dhcp_state();
      if( dhcpState != DHCP_STATE_OK ) {
        if (millis() > (lastDhcpRequest + 10000L) ){
          lastDhcpRequest = millis();
	  if( --dhcpTries <= 0 ) 
		  return 0;		
          dhcp_start( buf, mymac, myip, mynetmask,gwip, dnsip, dhcpsvrip );
        }
      } else {
        if( !gotIp ) {
          gotIp = true;
          init_ip_arp_udp_tcp(mymac, myip, myport);
          client_set_gwip(gwip);  
          dnslkup_set_dnsip( dnsip );
        }
      }
    }
  }
  return 1;
}
uint8_t EtherShield :: allocateIPAddress ( uint8_t * buf , uint16_t buffer_size , uint8_t * mymac , uint16_t myport , uint8_t * myip , uint8_t * mynetmask , uint8_t * gwip , uint8_t * dnsip , uint8_t * dhcpsvrip ) { uint16_t dat_p ; int plen = 0 ; long lastDhcpRequest = millis ( ) ; uint8_t dhcpState = 0 ; boolean gotIp = false ; uint8_t dhcpTries = 10 ; dhcp_start ( buf , mymac , myip , mynetmask , gwip , dnsip , dhcpsvrip ) ; while ( ! gotIp ) { plen = enc28j60PacketReceive ( buffer_size , buf ) ; dat_p = packetloop_icmp_tcp ( buf , plen ) ; if ( dat_p == 0 ) { int retstat = check_for_dhcp_answer ( buf , plen ) ; dhcpState = dhcp_state ( ) ; if ( dhcpState != DHCP_STATE_OK ) { if ( millis ( ) > ( lastDhcpRequest + 10000L ) ) { lastDhcpRequest = millis ( ) ; if ( -- dhcpTries <= 0 ) return 0 ; dhcp_start ( buf , mymac , myip , mynetmask , gwip , dnsip , dhcpsvrip ) ; } } else { if ( ! gotIp ) { gotIp = true ; init_ip_arp_udp_tcp ( mymac , myip , myport ) ; client_set_gwip ( gwip ) ; dnslkup_set_dnsip ( dnsip ) ; } } } } return 1 ; }
Perform all processing to get an IP address plus other addresses returned, e.g.
Perform all processing to get an IP address plus other addresses returned e . g .
// After 10 attempts fail gracefully so other action can be carried out // handle ping and wait for a tcp packet // we are idle here // Failed to allocate address // send dhcp //init the ethernet/ip layer: // Set the Router IP // e.g internal IP of dsl router // Set the DNS server IP address if required, or use default