/* Initialise the resolver. Open a socket and bind it to the address of the server. return -1 if something goes wrong, otherwise 0 */ int redboot_dns_res_init(void) { memset((char *)&server, 0, sizeof(server)); server.sin_len = sizeof(server); server.sin_family = AF_INET; server.sin_port = htons(DOMAIN_PORT); cyg_drv_mutex_init(&dns_mutex); #ifdef CYGSEM_REDBOOT_FLASH_CONFIG { ip_addr_t dns_ip; flash_get_config("dns_ip", &dns_ip, CONFIG_IP); if (dns_ip[0] == 0 && dns_ip[1] == 0 && dns_ip[2] == 0 && dns_ip[3] == 0) return -1; memcpy(&server.sin_addr, &dns_ip, sizeof(dns_ip)); /* server config is valid */ s = 0; } #else // Use static configuration set_dns(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_IP)); #endif return 0; }
void do_ip_addr(int argc, char *argv[]) { struct option_info opts[3]; char *ip_addr, *host_addr; bool ip_addr_set, host_addr_set; struct sockaddr_in host; #ifdef CYGPKG_REDBOOT_NETWORKING_DNS char *dns_addr; bool dns_addr_set; #endif int num_opts; init_opts(&opts[0], 'l', true, OPTION_ARG_TYPE_STR, (void **)&ip_addr, (bool *)&ip_addr_set, "local IP address"); init_opts(&opts[1], 'h', true, OPTION_ARG_TYPE_STR, (void **)&host_addr, (bool *)&host_addr_set, "default server address"); num_opts = 2; #ifdef CYGPKG_REDBOOT_NETWORKING_DNS init_opts(&opts[2], 'd', true, OPTION_ARG_TYPE_STR, (void **)&dns_addr, (bool *)&dns_addr_set, "DNS server address"); num_opts++; #endif if (!scan_opts(argc, argv, 1, opts, num_opts, 0, 0, "")) { return; } if (ip_addr_set) { if (!_gethostbyname(ip_addr, (in_addr_t *)&host)) { diag_printf("Invalid local IP address: %s\n", ip_addr); return; } // Of course, each address goes in its own place :-) memcpy(&__local_ip_addr, &host.sin_addr, sizeof(host.sin_addr)); } if (host_addr_set) { if (!_gethostbyname(host_addr, (in_addr_t *)&host)) { diag_printf("Invalid server address: %s\n", host_addr); return; } my_bootp_info.bp_siaddr = host.sin_addr; } #ifdef CYGPKG_REDBOOT_NETWORKING_DNS if (dns_addr_set) { set_dns(dns_addr); } #endif show_addrs(); if (!have_net) { have_net = true; net_io_init(); } }
/* Initialise the resolver. Open a socket and bind it to the address of the server. return -1 if something goes wrong, otherwise 0 */ int redboot_dns_res_init(void) { #ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN char *dns_domain = NULL; #endif memset((char *)&server, 0, sizeof(server)); server.sin_len = sizeof(server); server.sin_family = AF_INET; server.sin_port = htons(DOMAIN_PORT); cyg_drv_mutex_init(&dns_mutex); /* Set the default DNS domain first, so that it can be overwritten latter */ #ifdef CYGPKG_REDBOOT_NETWORKING_DNS_DEFAULT_DOMAIN setdomainname(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_DEFAULT_DOMAIN), strlen(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_DEFAULT_DOMAIN))); #endif /* Set the domain name from flash so that DHCP can later overwrite it. */ #ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN flash_get_config("dns_domain", &dns_domain, CONFIG_STRING); if(dns_domain != NULL && dns_domain[0] != '\0') setdomainname(dns_domain, strlen(dns_domain)); #endif /* If we got a DNS server address from the DHCP/BOOTP, then use that address */ if ( __bootp_dns_set ) { memcpy(&server.sin_addr, &__bootp_dns_addr, sizeof(__bootp_dns_addr) ); #ifdef CYGPKG_REDBOOT_NETWORKING_DNS_DHCP_DOMAIN if(__bootp_dns_domain_set) setdomainname(__bootp_dns_domain, strlen(__bootp_dns_domain)); #endif /* server config is valid */ s = 0; } else { #ifdef CYGSEM_REDBOOT_FLASH_CONFIG { ip_addr_t dns_ip; flash_get_config("dns_ip", &dns_ip, CONFIG_IP); if (dns_ip[0] == 0 && dns_ip[1] == 0 && dns_ip[2] == 0 && dns_ip[3] == 0) return -1; memcpy(&server.sin_addr, &dns_ip, sizeof(dns_ip)); /* server config is valid */ s = 0; } #else // Use static configuration. If CYGPKG_REDBOOT_NETWORKING_DNS_IP // is valid s will set set as a side effect. set_dns(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_IP)); #endif } return 0; }
void do_ip_addr(int argc, char *argv[]) { struct option_info opts[3]; char *ip_addr, *host_addr; bool ip_addr_set, host_addr_set; struct sockaddr_in host; #ifdef CYGPKG_REDBOOT_NETWORKING_DNS char *dns_addr; bool dns_addr_set; #endif int num_opts; init_opts(&opts[0], 'l', true, OPTION_ARG_TYPE_STR, (void *)&ip_addr, (bool *)&ip_addr_set, "local IP address"); init_opts(&opts[1], 'h', true, OPTION_ARG_TYPE_STR, (void *)&host_addr, (bool *)&host_addr_set, "default server address"); num_opts = 2; #ifdef CYGPKG_REDBOOT_NETWORKING_DNS init_opts(&opts[2], 'd', true, OPTION_ARG_TYPE_STR, (void *)&dns_addr, (bool *)&dns_addr_set, "DNS server address"); num_opts++; #endif CYG_ASSERT(num_opts <= NUM_ELEMS(opts), "Too many options"); if (!scan_opts(argc, argv, 1, opts, num_opts, 0, 0, "")) { return; } if (ip_addr_set) { #ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY char *slash_pos; /* see if the (optional) mask length was given */ if( (slash_pos = strchr(ip_addr, '/')) ) { int mask_len; unsigned long mask; *slash_pos = '\0'; slash_pos++; if( !parse_num(slash_pos, (unsigned long *)&mask_len, 0, 0) || mask_len <= 0 || mask_len > 32 ) { diag_printf("Invalid mask length: %s\n", slash_pos); return; } mask = htonl((0xffffffff << (32-mask_len))&0xffffffff); memcpy(&__local_ip_mask, &mask, 4); } #endif if (!_gethostbyname(ip_addr, (in_addr_t *)&host)) { diag_printf("Invalid local IP address: %s\n", ip_addr); return; } // Of course, each address goes in its own place :-) memcpy(&__local_ip_addr, &host.sin_addr, sizeof(host.sin_addr)); } if (host_addr_set) { if (!_gethostbyname(host_addr, (in_addr_t *)&host)) { diag_printf("Invalid server address: %s\n", host_addr); return; } my_bootp_info.bp_siaddr = host.sin_addr; } #ifdef CYGPKG_REDBOOT_NETWORKING_DNS if (dns_addr_set) { set_dns(dns_addr); } #endif show_addrs(); if (!have_net) { have_net = true; net_io_init(); } }