summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-12-11 23:10:47 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-12-11 23:10:47 +0000
commit5fe3de54cf5d76704b60d598169031aad2b7130f (patch)
tree1c8117124d99672db1995756969e5f78b73f3782
parent6ec9360372086c2f466ef223e22d5e9412b46da1 (diff)
downloadnuttx-5fe3de54cf5d76704b60d598169031aad2b7130f.tar.gz
nuttx-5fe3de54cf5d76704b60d598169031aad2b7130f.tar.bz2
nuttx-5fe3de54cf5d76704b60d598169031aad2b7130f.zip
Need to preserve IP address from spurious OFFERs as well
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@449 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/netutils/dhcpc/dhcpc.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/nuttx/netutils/dhcpc/dhcpc.c b/nuttx/netutils/dhcpc/dhcpc.c
index 4af16f6a1..96d945aa6 100644
--- a/nuttx/netutils/dhcpc/dhcpc.c
+++ b/nuttx/netutils/dhcpc/dhcpc.c
@@ -125,6 +125,7 @@ struct dhcpc_state_s
const void *ds_macaddr;
int ds_maclen;
int sockfd;
+ struct in_addr ipaddr;
struct in_addr serverid;
struct dhcp_msg packet;
};
@@ -160,11 +161,11 @@ static uint8 *dhcpc_addserverid(struct in_addr *serverid, uint8 *optptr)
return optptr + 4;
}
-static uint8 *dhcpc_addreqipaddr(struct dhcpc_state *presult, uint8 *optptr)
+static uint8 *dhcpc_addreqipaddr(struct in_addr *ipaddr, uint8 *optptr)
{
*optptr++ = DHCP_OPTION_REQ_IPADDR;
*optptr++ = 4;
- memcpy(optptr, &presult->ipaddr.s_addr, 4);
+ memcpy(optptr, &ipaddr->s_addr, 4);
return optptr + 4;
}
@@ -223,16 +224,16 @@ static int dhcpc_sendmsg(struct dhcpc_state_s *pdhcpc,
pend = dhcpc_addreqoptions(pend);
break;
- /* Send REQUEST message to the server that send the OFFER */
+ /* Send REQUEST message to the server that sent the *first* OFFER */
case DHCPREQUEST:
pdhcpc->packet.flags = HTONS(BOOTP_BROADCAST); /* Broadcast bit. */
- memcpy(pdhcpc->packet.ciaddr, &presult->ipaddr.s_addr, 4);
+ memcpy(pdhcpc->packet.ciaddr, &pdhcpc->ipaddr.s_addr, 4);
pend = dhcpc_addserverid(&pdhcpc->serverid, pend);
- pend = dhcpc_addreqipaddr(presult, pend);
+ pend = dhcpc_addreqipaddr(&pdhcpc->ipaddr, pend);
break;
- /* Send DECLINE message to the server that sent the OFFER */
+ /* Send DECLINE message to the server that sent the *last* OFFER */
case DHCPDECLINE:
memcpy(pdhcpc->packet.ciaddr, &presult->ipaddr.s_addr, 4);
@@ -451,7 +452,8 @@ int dhcpc_request(void *handle, struct dhcpc_state *presult)
*/
dbg("Received OFFER from %08x\n", ntohl(presult->serverid.s_addr));
- pdhcpc->serverid.s_addr = presult->serverid.s_addr;
+ pdhcpc->ipaddr.s_addr = presult->ipaddr.s_addr;
+ pdhcpc->serverid.s_addr = presult->serverid.s_addr;
/* Temporarily use the address offered by the server and break
* out of the loop.