int16_t parse_cmd_ntp_server(char *cmd, char *output, uint16_t len) { uip_ipaddr_t ntpaddr; while (*cmd == ' ') cmd++; if (*cmd != '\0') { /* try to parse ip */ if (parse_ip(cmd, &ntpaddr) != 0) { #ifdef DNS_SUPPORT uip_ipaddr_t *ip; if (!(ip = resolv_lookup(cmd))) resolv_query(cmd, ntp_dns_query_cb); else ntp_conf(ip); #else return ECMD_ERR_PARSE_ERROR; #endif } else ntp_conf(&ntpaddr); return ECMD_FINAL_OK; } else { return ECMD_FINAL(print_ipaddr(ntp_getserver(), output, len)); } }
void ntp_init() { #ifdef DNS_SUPPORT uip_ipaddr_t *ipaddr; if (!(ipaddr = resolv_lookup(NTP_SERVER))) resolv_query(NTP_SERVER, ntp_dns_query_cb); else ntp_conf(ipaddr); #else /* ! DNS_SUPPORT */ uip_ipaddr_t ip; set_NTP_SERVER_IP(&ip); ntp_conf(&ip); #endif }
void ntp_init() { #ifdef DNS_SUPPORT ntp_tries = 0; // reset try counter uip_ipaddr_t *ipaddr; if (ntp_conn != NULL || !(ipaddr = resolv_lookup(NTP_SERVER))) resolv_query(NTP_SERVER, ntp_dns_query_cb); else ntp_conf(ipaddr); #else /* ! DNS_SUPPORT */ uip_ipaddr_t ip; set_NTP_SERVER_IP(&ip); ntp_conf(&ip); #endif }
void ntp_dns_query_cb(char *name, uip_ipaddr_t *ipaddr) { ntp_conf(ipaddr); #ifdef DEBUG_NTP debug_printf("NTP: query connected\n"); #endif }
void ntp_init() { #ifdef DNS_SUPPORT uip_ipaddr_t *ipaddr; if (!(ipaddr = resolv_lookup(NTP_SERVER))) resolv_query(NTP_SERVER, ntp_dns_query_cb); else ntp_conf(ipaddr); #else /* ! DNS_SUPPORT */ uip_ipaddr_t ip; // set_NTP_SERVER_IP(&ip); eeprom_restore(ntp_server, &ip, IPADDR_LEN); ntp_conf(&ip); #endif }
void bootp_handle_reply(void) { int i; struct bootp *pk = uip_appdata; if(pk->bp_op != BOOTREPLY) return; /* ugh? shouldn't happen */ if(pk->bp_htype != HTYPE_ETHERNET) return; for(i = 0; i < 4; i ++) { if(pk->bp_xid[i] != uip_udp_conn->appstate.bootp.xid[i]) return; /* session id doesn't match */ if(pk->bp_vend[i] != replycookie[i]) return; /* reply cookie doesn't match */ } /* * looks like we have received a valid bootp reply, * prepare to override eeprom configuration */ uip_ipaddr_t ips[5]; memset(&ips, 0, sizeof(ips)); /* extract our ip addresses, subnet-mask and gateway ... */ memcpy(&ips[0], pk->bp_yiaddr, 4); uip_sethostaddr(&ips[0]); debug_printf ("BOOTP: configured new ip address %d.%d.%d.%d\n", ((unsigned char *) ips)[0], ((unsigned char *) ips)[1], ((unsigned char *) ips)[2], ((unsigned char *) ips)[3]); unsigned char *ptr = pk->bp_vend + 4; while(*ptr != 0xFF) { switch(* ptr) { case TAG_SUBNET_MASK: memcpy(&ips[1], &ptr[2], 4); uip_setnetmask(&ips[1]); break; case TAG_GATEWAY: memcpy(&ips[2], &ptr[2], 4); uip_setdraddr(&ips[2]); break; #ifdef DNS_SUPPORT case TAG_DOMAIN_SERVER: memcpy(&ips[3], &ptr[2], 4); resolv_conf(&ips[3]); break; #endif #ifdef NTP_SUPPORT case TAG_NTP_SERVER: /* This will set the ntp connection to the server set by the bootp * request */ memcpy(&ips[4], &ptr[2], 4); ntp_conf(&ips[4]); break; #endif } ptr = ptr + ptr[1] + 2; } /* Remove the bootp connection */ uip_udp_remove(uip_udp_conn); #ifdef BOOTP_TO_EEPROM_SUPPORT eeprom_save(ip, &ips[0], IPADDR_LEN); eeprom_save(netmask, &ips[1], IPADDR_LEN); eeprom_save(gateway, &ips[2], IPADDR_LEN); #ifdef DNS_SUPPORT eeprom_save(dns_server, &ips[3], IPADDR_LEN); #endif #ifdef NTP_SUPPORT eeprom_save(ntp_server, &ips[4], IPADDR_LEN); #endif #endif /* BOOTP_TO_EEPROM_SUPPORT */ #ifdef DYNDNS_SUPPORT dyndns_update(); #endif #if defined(TFTP_SUPPORT) && defined(BOOTLOADER_SUPPORT) if(pk->bp_file[0] == 0) return; /* no boot filename provided */ debug_putstr("load:"); debug_putstr(pk->bp_file); debug_putchar('\n'); /* create tftp connection, which will fire the download request */ uip_ipaddr_t ip; uip_ipaddr(&ip, pk->bp_siaddr[0], pk->bp_siaddr[1], pk->bp_siaddr[2], pk->bp_siaddr[3]); tftp_fire_tftpomatic(&ip, pk->bp_file); #endif /* TFTP_SUPPORT */ }