comparison packages/redboot/current/src/net/dns.c @ 1357:7b0dae4bd7a9

Use DNS server from DHCP info if present
author gthomas
date Fri, 07 Nov 2003 18:14:10 +0000
parents d2c90368aeef
children
comparison
equal deleted inserted replaced
1356:6a23e2474d97 1357:7b0dae4bd7a9
7 //============================================================================= 7 //=============================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN#### 8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // ------------------------------------------- 9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System. 10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2003 Gary Thomas
12 // 13 //
13 // eCos is free software; you can redistribute it and/or modify it under 14 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free 15 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version. 16 // Software Foundation; either version 2 or (at your option) any later version.
16 // 17 //
80 #define DOMAIN_PORT 53 81 #define DOMAIN_PORT 53
81 82
82 /* Some magic to make dns_impl.inl compile under RedBoot */ 83 /* Some magic to make dns_impl.inl compile under RedBoot */
83 #define sprintf diag_sprintf 84 #define sprintf diag_sprintf
84 85
86 /* DNS server address possibly returned from bootp */
87 struct in_addr __bootp_dns_addr;
88 cyg_bool __bootp_dns_set = false;
89
85 struct sockaddr_in server; 90 struct sockaddr_in server;
86 91
87 /* static buffers so we can make do without malloc */ 92 /* static buffers so we can make do without malloc */
88 static struct hostent _hent; 93 static struct hostent _hent;
89 static char* _h_addr_list[2]; 94 static char* _h_addr_list[2];
250 server.sin_len = sizeof(server); 255 server.sin_len = sizeof(server);
251 server.sin_family = AF_INET; 256 server.sin_family = AF_INET;
252 server.sin_port = htons(DOMAIN_PORT); 257 server.sin_port = htons(DOMAIN_PORT);
253 cyg_drv_mutex_init(&dns_mutex); 258 cyg_drv_mutex_init(&dns_mutex);
254 259
260 /* If we got a DNS server address from the DHCP/BOOTP, then use that address */
261 if ( __bootp_dns_set ) {
262 memcpy(&server.sin_addr, &__bootp_dns_addr, sizeof(__bootp_dns_addr) );
263 s = 0;
264 }
265 else {
255 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG 266 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
256 { 267 {
257 ip_addr_t dns_ip; 268 ip_addr_t dns_ip;
258 269
259 flash_get_config("dns_ip", &dns_ip, CONFIG_IP); 270 flash_get_config("dns_ip", &dns_ip, CONFIG_IP);
262 memcpy(&server.sin_addr, &dns_ip, sizeof(dns_ip)); 273 memcpy(&server.sin_addr, &dns_ip, sizeof(dns_ip));
263 /* server config is valid */ 274 /* server config is valid */
264 s = 0; 275 s = 0;
265 } 276 }
266 #else 277 #else
267 // Use static configuration 278 // Use static configuration
268 set_dns(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_IP)); 279 set_dns(__Xstr(CYGPKG_REDBOOT_NETWORKING_DNS_IP));
269 #endif 280 #endif
281 }
270 282
271 return 0; 283 return 0;
272 } 284 }
273 285
274 /* Include the DNS client implementation code */ 286 /* Include the DNS client implementation code */