[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-devel] DHCP Improvement
From: |
Craig Graham |
Subject: |
[lwip-devel] DHCP Improvement |
Date: |
Wed, 21 Jul 2004 12:26:21 +0100 |
User-agent: |
KMail/1.6 |
This patch add's DNS server query to the lwip DHCP implementation (so you can
get the DNS server address' at the same time as your IP address).
The DNS server's for an interface can then be accessed via:
netif->dhcp->dns_count == number of DNS server's discovered (0 - 2)
netif->dhcp->offered_dns_addr[0] == primary DNS server
netif->dhcp->offered_dns_addr[1] == secondary DNS server
Laters,
Craig.
--- ./orig/lwip-0.7.2/src/include/lwip/dhcp.h 2003-12-28 02:38:51.000000000
+0000
+++ ./lwip-0.7.2/src/include/lwip/dhcp.h 2004-07-20 15:15:47.000000000
+0100
@@ -43,6 +43,8 @@
struct ip_addr offered_sn_mask;
struct ip_addr offered_gw_addr;
struct ip_addr offered_bc_addr;
+ u32_t dns_count; //++cg[20/7/2004]: Number of DNS server
address' discovered
+ struct ip_addr offered_dns_addr[2]; //++cg[20/7/2004]: DNS server address'
u32_t offered_t0_lease; /* lease period (in seconds) */
u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease
period) */
u32_t offered_t2_rebind; /* recommended rebind time (usually 66% of lease
period) */
@@ -175,6 +177,8 @@
#define DHCP_OPTION_PAD 0
#define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */
#define DHCP_OPTION_ROUTER 3
+#define DHCP_OPTION_DNS_SERVER 6
--- ./orig/lwip-0.7.2/src/core/dhcp.c 2004-04-23 16:36:18.000000000 +0100
+++ ./lwip-0.7.2/src/core/dhcp.c 2004-07-20 15:23:03.000000000 +0100
@@ -231,10 +237,12 @@
dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4);
dhcp_option_long(dhcp, ntohl(dhcp->server_ip_addr.addr));
- dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 3);
+ dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 4);
dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK);
dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST);
+ //++cg[20/7/2004]: Request DNS server address from DHCP server
+ dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER);
dhcp_option_trailer(dhcp);
/* shrink the pbuf to the actual content length */
@@ -480,6 +488,24 @@
if (option_ptr != NULL) {
dhcp->offered_bc_addr.addr = htonl(dhcp_get_option_long(&option_ptr[2]));
}
+
+ //++cg[20/7/2004]: handle DHCP server
+ option_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_DNS_SERVER);
+ if (option_ptr != NULL) {
+ int n;
+ dhcp->dns_count=dhcp_get_option_byte(&option_ptr[1]);
+ if(dhcp->dns_count>2)
+ dhcp->dns_count=2;
+ printf("dhcp: got %lu DNS server address'\n",dhcp->dns_count);
+ for(n=0; n<dhcp->dns_count; n++)
+ {
+ struct in_addr inA;
+ dhcp->offered_dns_addr[n].addr =
htonl(dhcp_get_option_long(&option_ptr[2+(n<<2)]));
+ inA.s_addr=dhcp->offered_dns_addr[n].addr;
+ printf("dhcp: dns[%d] = %s\n",n,inet_ntoa(inA));
+ }
+ }
+
}
/**
@@ -695,10 +721,12 @@
dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE,
DHCP_OPTION_MAX_MSG_SIZE_LEN);
dhcp_option_short(dhcp, 576);
- dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 3);
+ dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 4);
dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK);
dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER);
dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST);
+ //++cg[20/7/2004]: Request DNS server address from DHCP server
+ dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER);
dhcp_option_trailer(dhcp);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lwip-devel] DHCP Improvement,
Craig Graham <=