dhcpd_allocipaddr() should not call ntohl(). The return value is already in host order. From Brennan Ashton

This commit is contained in:
Gregory Nutt 2014-03-03 17:46:56 -06:00
parent 003c3ded18
commit 9b172004c0
2 changed files with 59 additions and 39 deletions

View File

@ -851,3 +851,6 @@
'cat' command. This prevents the NSH prompt from be in the same line 'cat' command. This prevents the NSH prompt from be in the same line
as the final line of the file in the case where there is no newline as the final line of the file in the case where there is no newline
at the end of the file (2014-2-27). at the end of the file (2014-2-27).
* netutils/dhcpd/dhcpd.c: allocipaddr() should not call ntohl(), the
returned IP address is already in host order.

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* netutils/dhcpd/dhcpd.c * netutils/dhcpd/dhcpd.c
* *
* Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -300,6 +300,7 @@ static time_t dhcpd_time(void)
{ {
ret = ts.tv_sec; ret = ts.tv_sec;
} }
return ret; return ret;
} }
#else #else
@ -404,6 +405,7 @@ static struct lease_s *dhcpd_findbyipaddr(in_addr_t ipaddr)
return lease; return lease;
} }
} }
return NULL; return NULL;
} }
@ -411,7 +413,7 @@ static struct lease_s *dhcpd_findbyipaddr(in_addr_t ipaddr)
* Name: dhcpd_allocipaddr * Name: dhcpd_allocipaddr
****************************************************************************/ ****************************************************************************/
in_addr_t dhcpd_allocipaddr(void) static in_addr_t dhcpd_allocipaddr(void)
{ {
struct lease_s *lease = NULL; struct lease_s *lease = NULL;
in_addr_t ipaddr; in_addr_t ipaddr;
@ -419,11 +421,15 @@ in_addr_t dhcpd_allocipaddr(void)
ipaddr = CONFIG_NETUTILS_DHCPD_STARTIP; ipaddr = CONFIG_NETUTILS_DHCPD_STARTIP;
for (; ipaddr <= CONFIG_NETUTILS_DHCP_OPTION_ENDIP; ipaddr++) for (; ipaddr <= CONFIG_NETUTILS_DHCP_OPTION_ENDIP; ipaddr++)
{ {
/* Skip over address ending in 0 or 255 */
if ((ipaddr & 0xff) == 0 || (ipaddr & 0xff) == 0xff) if ((ipaddr & 0xff) == 0 || (ipaddr & 0xff) == 0xff)
{ {
continue; continue;
} }
/* Is there already a lease on this address? If so, has it expired? */
lease = dhcpd_findbyipaddr(ipaddr); lease = dhcpd_findbyipaddr(ipaddr);
if ((!lease || dhcpd_leaseexpired(lease))) if ((!lease || dhcpd_leaseexpired(lease)))
{ {
@ -436,9 +442,12 @@ in_addr_t dhcpd_allocipaddr(void)
#ifdef HAVE_LEASE_TIME #ifdef HAVE_LEASE_TIME
g_state.ds_leases[ipaddr - CONFIG_NETUTILS_DHCPD_STARTIP].expiry = dhcpd_time() + CONFIG_NETUTILS_DHCPD_OFFERTIME; g_state.ds_leases[ipaddr - CONFIG_NETUTILS_DHCPD_STARTIP].expiry = dhcpd_time() + CONFIG_NETUTILS_DHCPD_OFFERTIME;
#endif #endif
return ntohl(ipaddr); /* Return the address in host order */
return ipaddr;
} }
} }
return 0; return 0;
} }
@ -595,6 +604,7 @@ static inline bool dhcpd_parseoptions(void)
remaining -= optlen; remaining -= optlen;
} }
while (remaining > 0); while (remaining > 0);
return false; return false;
} }
@ -622,6 +632,7 @@ static inline bool dhcpd_verifyreqip(void)
return true; return true;
} }
} }
return false; return false;
} }
@ -653,6 +664,7 @@ static inline bool dhcpd_verifyreqleasetime(uint32_t *leasetime)
*leasetime = tmp; *leasetime = tmp;
return true; return true;
} }
return false; return false;
} }
@ -681,6 +693,7 @@ static int dhcpd_addoption(uint8_t *option)
*g_state.ds_optend = DHCP_OPTION_END; *g_state.ds_optend = DHCP_OPTION_END;
} }
} }
return len; return len;
} }
@ -1259,6 +1272,7 @@ static inline int dhcpd_decline(void)
lease->expiry = dhcpd_time() + CONFIG_NETUTILS_DHCPD_DECLINETIME; lease->expiry = dhcpd_time() + CONFIG_NETUTILS_DHCPD_DECLINETIME;
#endif #endif
} }
return OK; return OK;
} }
@ -1275,6 +1289,7 @@ static inline int dhcpd_release(void)
memset(lease, 0, sizeof(struct lease_s)); memset(lease, 0, sizeof(struct lease_s));
} }
return OK; return OK;
} }
@ -1308,6 +1323,7 @@ static inline int dhcpd_openlistener(void)
close(sockfd); close(sockfd);
return ERROR; return ERROR;
} }
g_state.ds_serverip = ((struct sockaddr_in*)&req.ifr_addr)->sin_addr.s_addr; g_state.ds_serverip = ((struct sockaddr_in*)&req.ifr_addr)->sin_addr.s_addr;
nvdbg("serverip: %08lx\n", ntohl(g_state.ds_serverip)); nvdbg("serverip: %08lx\n", ntohl(g_state.ds_serverip));
@ -1429,5 +1445,6 @@ int dhcpd_run(void)
break; break;
} }
} }
return OK; return OK;
} }