mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
netutils/dhcpc/dhcpc: add implementation to get renewal (T1) time and
rebinding (T2) time from DHCP packet. According to RFC 2131, T1 and T2 times play a critical role in lease management in DHCP clients. Signed-off-by: nuttxs <zhaoqing.zhang@sony.com>
This commit is contained in:
parent
8d2a7e32a5
commit
8f3c3c57f9
2 changed files with 37 additions and 1 deletions
|
|
@ -58,6 +58,8 @@ struct dhcpc_state
|
|||
struct in_addr dnsaddr;
|
||||
struct in_addr default_router;
|
||||
uint32_t lease_time; /* Lease expires in this number of seconds */
|
||||
uint32_t renewal_time; /* Seconds to transition to RENEW state(T1) */
|
||||
uint32_t rebinding_time; /* Seconds to transition to REBIND state(T2) */
|
||||
};
|
||||
|
||||
typedef void (*dhcpc_callback_t)(FAR struct dhcpc_state *presult);
|
||||
|
|
|
|||
|
|
@ -96,6 +96,8 @@
|
|||
#define DHCP_OPTION_MSG_TYPE 53
|
||||
#define DHCP_OPTION_SERVER_ID 54
|
||||
#define DHCP_OPTION_REQ_LIST 55
|
||||
#define DHCP_OPTION_T1_TIME 58
|
||||
#define DHCP_OPTION_T2_TIME 59
|
||||
#define DHCP_OPTION_CLIENT_ID 61
|
||||
#define DHCP_OPTION_END 255
|
||||
|
||||
|
|
@ -340,6 +342,7 @@ static uint8_t dhcpc_parseoptions(FAR struct dhcpc_state *presult,
|
|||
{
|
||||
FAR uint8_t *end = optptr + len;
|
||||
uint8_t type = 0;
|
||||
uint16_t tmp[2];
|
||||
|
||||
while (optptr < end)
|
||||
{
|
||||
|
|
@ -421,7 +424,6 @@ static uint8_t dhcpc_parseoptions(FAR struct dhcpc_state *presult,
|
|||
|
||||
if (optptr + 6 <= end)
|
||||
{
|
||||
uint16_t tmp[2];
|
||||
memcpy(tmp, optptr + 2, 4);
|
||||
presult->lease_time = ((uint32_t)ntohs(tmp[0])) << 16 |
|
||||
(uint32_t)ntohs(tmp[1]);
|
||||
|
|
@ -432,6 +434,38 @@ static uint8_t dhcpc_parseoptions(FAR struct dhcpc_state *presult,
|
|||
}
|
||||
break;
|
||||
|
||||
case DHCP_OPTION_T1_TIME:
|
||||
|
||||
/* Get renewal (T1) time (in seconds) in host order */
|
||||
|
||||
if (optptr + 6 <= end)
|
||||
{
|
||||
memcpy(tmp, optptr + 2, 4);
|
||||
presult->renewal_time = ((uint32_t)ntohs(tmp[0])) << 16 |
|
||||
(uint32_t)ntohs(tmp[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
nerr("Packet too short (renewal time missing)\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case DHCP_OPTION_T2_TIME:
|
||||
|
||||
/* Get rebinding (T2) time (in seconds) in host order */
|
||||
|
||||
if (optptr + 6 <= end)
|
||||
{
|
||||
memcpy(tmp, optptr + 2, 4);
|
||||
presult->rebinding_time = ((uint32_t)ntohs(tmp[0])) << 16 |
|
||||
(uint32_t)ntohs(tmp[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
nerr("Packet too short (rebinding time missing)\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case DHCP_OPTION_END:
|
||||
return type;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue