Skip to content
Snippets Groups Projects
Commit f71c623c authored by patacongo's avatar patacongo
Browse files

Lease time is now in host order

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2839 42af7a65-404d-4744-a932-0658087f49c3
parent 96664e98
No related branches found
No related tags found
No related merge requests found
......@@ -839,7 +839,9 @@ int nsh_telnetmain(int argc, char *argv[])
handle = dhcpc_open(&mac, IFHWADDRLEN);
/* Get an IP address */
/* Get an IP address. Note that there is no logic for renewing the IP address in this
* example. The address should be renewed in ds.lease_time/2 seconds.
*/
if (handle)
{
......
......@@ -170,7 +170,9 @@ int user_start(int argc, char *argv[])
handle = dhcpc_open(&mac, IFHWADDRLEN);
/* Get an IP address */
/* Get an IP address. Note: there is no logic here for renewing the address in this
* example. The address should be renewed in ds.lease_time/2 seconds.
*/
printf("Getting IP address\n");
if (handle)
......
/****************************************************************************
* net/uip/dhcpc.n
*
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* This logic was leveraged from uIP which also has a BSD-style license:
......@@ -54,12 +54,12 @@
struct dhcpc_state
{
uint16_t lease_time[2];
struct in_addr serverid;
struct in_addr ipaddr;
struct in_addr netmask;
struct in_addr dnsaddr;
struct in_addr default_router;
uint32_t lease_time; /* Lease expires in this number of seconds */
};
/****************************************************************************
......
......@@ -273,23 +273,45 @@ static uint8_t dhcpc_parseoptions(struct dhcpc_state *presult, uint8_t *optptr,
switch(*optptr)
{
case DHCP_OPTION_SUBNET_MASK:
/* Get subnet mask in network order */
memcpy(&presult->netmask.s_addr, optptr + 2, 4);
break;
case DHCP_OPTION_ROUTER:
/* Get the default router address in network order */
memcpy(&presult->default_router.s_addr, optptr + 2, 4);
break;
case DHCP_OPTION_DNS_SERVER:
/* Get the DNS server address in network order */
memcpy(&presult->dnsaddr.s_addr, optptr + 2, 4);
break;
case DHCP_OPTION_MSG_TYPE:
/* Get message type */
type = *(optptr + 2);
break;
case DHCP_OPTION_SERVER_ID:
/* Get server address in network order */
memcpy(&presult->serverid.s_addr, optptr + 2, 4);
break;
case DHCP_OPTION_LEASE_TIME:
memcpy(presult->lease_time, optptr + 2, 4);
{
/* Get lease time (in seconds) in host order */
uint16_t tmp[2];
memcpy(tmp, optptr + 2, 4);
presult->lease_time = ((uint32_t)ntohs(tmp[0])) << 16 | (uint32_t)ntohs(tmp[1]);
}
break;
case DHCP_OPTION_END:
return type;
}
......@@ -580,7 +602,6 @@ int dhcpc_request(void *handle, struct dhcpc_state *presult)
(presult->default_router.s_addr >> 16 ) & 0xff,
(presult->default_router.s_addr >> 8 ) & 0xff,
(presult->default_router.s_addr ) & 0xff);
dbg("Lease expires in %ld seconds\n",
ntohs(presult->lease_time[0])*65536ul + ntohs(presult->lease_time[1]));
dbg("Lease expires in %d seconds\n", presult->lease_time);
return OK;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment