dhcpd_allocipaddr() should not call ntohl(). The return value is already in host order. From Brennan Ashton
This commit is contained in:
parent
003c3ded18
commit
9b172004c0
@ -851,3 +851,6 @@
|
||||
'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
|
||||
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.
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* 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>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
@ -404,6 +405,7 @@ static struct lease_s *dhcpd_findbyipaddr(in_addr_t ipaddr)
|
||||
return lease;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -411,7 +413,7 @@ static struct lease_s *dhcpd_findbyipaddr(in_addr_t ipaddr)
|
||||
* Name: dhcpd_allocipaddr
|
||||
****************************************************************************/
|
||||
|
||||
in_addr_t dhcpd_allocipaddr(void)
|
||||
static in_addr_t dhcpd_allocipaddr(void)
|
||||
{
|
||||
struct lease_s *lease = NULL;
|
||||
in_addr_t ipaddr;
|
||||
@ -419,11 +421,15 @@ in_addr_t dhcpd_allocipaddr(void)
|
||||
ipaddr = CONFIG_NETUTILS_DHCPD_STARTIP;
|
||||
for (; ipaddr <= CONFIG_NETUTILS_DHCP_OPTION_ENDIP; ipaddr++)
|
||||
{
|
||||
/* Skip over address ending in 0 or 255 */
|
||||
|
||||
if ((ipaddr & 0xff) == 0 || (ipaddr & 0xff) == 0xff)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Is there already a lease on this address? If so, has it expired? */
|
||||
|
||||
lease = dhcpd_findbyipaddr(ipaddr);
|
||||
if ((!lease || dhcpd_leaseexpired(lease)))
|
||||
{
|
||||
@ -436,9 +442,12 @@ in_addr_t dhcpd_allocipaddr(void)
|
||||
#ifdef HAVE_LEASE_TIME
|
||||
g_state.ds_leases[ipaddr - CONFIG_NETUTILS_DHCPD_STARTIP].expiry = dhcpd_time() + CONFIG_NETUTILS_DHCPD_OFFERTIME;
|
||||
#endif
|
||||
return ntohl(ipaddr);
|
||||
/* Return the address in host order */
|
||||
|
||||
return ipaddr;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -595,6 +604,7 @@ static inline bool dhcpd_parseoptions(void)
|
||||
remaining -= optlen;
|
||||
}
|
||||
while (remaining > 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -622,6 +632,7 @@ static inline bool dhcpd_verifyreqip(void)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -653,6 +664,7 @@ static inline bool dhcpd_verifyreqleasetime(uint32_t *leasetime)
|
||||
*leasetime = tmp;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -681,6 +693,7 @@ static int dhcpd_addoption(uint8_t *option)
|
||||
*g_state.ds_optend = DHCP_OPTION_END;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -1259,6 +1272,7 @@ static inline int dhcpd_decline(void)
|
||||
lease->expiry = dhcpd_time() + CONFIG_NETUTILS_DHCPD_DECLINETIME;
|
||||
#endif
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -1275,6 +1289,7 @@ static inline int dhcpd_release(void)
|
||||
|
||||
memset(lease, 0, sizeof(struct lease_s));
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -1308,6 +1323,7 @@ static inline int dhcpd_openlistener(void)
|
||||
close(sockfd);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
g_state.ds_serverip = ((struct sockaddr_in*)&req.ifr_addr)->sin_addr.s_addr;
|
||||
nvdbg("serverip: %08lx\n", ntohl(g_state.ds_serverip));
|
||||
|
||||
@ -1429,5 +1445,6 @@ int dhcpd_run(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user