# HG changeset patch # User gthomas # Date 1068228850 0 # Node ID 7b0dae4bd7a9765d602435d7cd95b29a5072f77f # Parent 6a23e2474d97c9c574f238ea3c3962833fb0091d Use DNS server from DHCP info if present diff --git a/packages/redboot/current/ChangeLog b/packages/redboot/current/ChangeLog --- a/packages/redboot/current/ChangeLog +++ b/packages/redboot/current/ChangeLog @@ -1,5 +1,10 @@ 2003-11-07 Gary Thomas + * src/net/dns.c: + * src/net/bootp.c: + * include/net/net.h: Use DNS server address from DHCP if provided. + Inspired by John Newlin + * src/flash.c (fis_init): Take out misleading warning - since the new [default] behaviour of "fis free" means free space need not be necessarily erased on the device. diff --git a/packages/redboot/current/include/net/net.h b/packages/redboot/current/include/net/net.h --- a/packages/redboot/current/include/net/net.h +++ b/packages/redboot/current/include/net/net.h @@ -359,6 +359,12 @@ extern ip_addr_t __local_ip_gate; extern ip_addr_t __local_ip_mask; #endif +#ifdef CYGPKG_REDBOOT_NETWORKING_DNS +extern struct in_addr __bootp_dns_addr; +extern cyg_bool __bootp_dns_set; +#endif + + /* * Set a timer. Caller is responsible for providing the timer_t struct. */ diff --git a/packages/redboot/current/src/net/bootp.c b/packages/redboot/current/src/net/bootp.c --- a/packages/redboot/current/src/net/bootp.c +++ b/packages/redboot/current/src/net/bootp.c @@ -288,6 +288,13 @@ int memcpy(__local_ip_gate,p,4); break; #endif +#ifdef CYGPKG_REDBOOT_NETWORKING_DNS + case TAG_DOMAIN_SERVER: + diag_printf(" DNS server found!\n"); + memcpy(&__bootp_dns_addr, p, 4); + __bootp_dns_set = 1; + break; +#endif default: break; } diff --git a/packages/redboot/current/src/net/dns.c b/packages/redboot/current/src/net/dns.c --- a/packages/redboot/current/src/net/dns.c +++ b/packages/redboot/current/src/net/dns.c @@ -9,6 +9,7 @@ // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +// Copyright (C) 2003 Gary Thomas // // eCos is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -82,6 +83,10 @@ static int get_port = 7700; /* Some magic to make dns_impl.inl compile under RedBoot */ #define sprintf diag_sprintf +/* DNS server address possibly returned from bootp */ +struct in_addr __bootp_dns_addr; +cyg_bool __bootp_dns_set = false; + struct sockaddr_in server; /* static buffers so we can make do without malloc */ @@ -252,6 +257,12 @@ redboot_dns_res_init(void) server.sin_port = htons(DOMAIN_PORT); cyg_drv_mutex_init(&dns_mutex); + /* 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) ); + s = 0; + } + else { #ifdef CYGSEM_REDBOOT_FLASH_CONFIG { ip_addr_t dns_ip; @@ -264,9 +275,10 @@ redboot_dns_res_init(void) s = 0; } #else - // Use static configuration - set_dns(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_IP)); + // Use static configuration + set_dns(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_IP)); #endif + } return 0; }