summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-08-10 16:39:34 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-08-10 16:39:34 +0000
commit9c8366a2361bbdb1bfe972ea583f5a28b54d8127 (patch)
treeeaea3f1d81289f66c33b3ddb649262949782fbe7 /nuttx
parent6fd590ce3bd9e85b121402ee44f47b0207d98e3e (diff)
downloadpx4-nuttx-9c8366a2361bbdb1bfe972ea583f5a28b54d8127.tar.gz
px4-nuttx-9c8366a2361bbdb1bfe972ea583f5a28b54d8127.tar.bz2
px4-nuttx-9c8366a2361bbdb1bfe972ea583f5a28b54d8127.zip
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
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/examples/nsh/nsh_telnetd.c4
-rw-r--r--nuttx/examples/uip/main.c4
-rw-r--r--nuttx/include/net/uip/dhcpc.h4
-rw-r--r--nuttx/netutils/dhcpc/dhcpc.c27
4 files changed, 32 insertions, 7 deletions
diff --git a/nuttx/examples/nsh/nsh_telnetd.c b/nuttx/examples/nsh/nsh_telnetd.c
index d9a590217..26a7f854a 100644
--- a/nuttx/examples/nsh/nsh_telnetd.c
+++ b/nuttx/examples/nsh/nsh_telnetd.c
@@ -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)
{
diff --git a/nuttx/examples/uip/main.c b/nuttx/examples/uip/main.c
index d5df1f807..39f451a26 100644
--- a/nuttx/examples/uip/main.c
+++ b/nuttx/examples/uip/main.c
@@ -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)
diff --git a/nuttx/include/net/uip/dhcpc.h b/nuttx/include/net/uip/dhcpc.h
index 8535c1b57..3d2fe4109 100644
--- a/nuttx/include/net/uip/dhcpc.h
+++ b/nuttx/include/net/uip/dhcpc.h
@@ -1,7 +1,7 @@
/****************************************************************************
* 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 */
};
/****************************************************************************
diff --git a/nuttx/netutils/dhcpc/dhcpc.c b/nuttx/netutils/dhcpc/dhcpc.c
index e35b0a116..79f806ad5 100644
--- a/nuttx/netutils/dhcpc/dhcpc.c
+++ b/nuttx/netutils/dhcpc/dhcpc.c
@@ -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;
}