diff --git a/include/netutils/dhcpc.h b/include/netutils/dhcpc.h index 4a5c451bd..3529e554f 100644 --- a/include/netutils/dhcpc.h +++ b/include/netutils/dhcpc.h @@ -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); diff --git a/netutils/dhcpc/dhcpc.c b/netutils/dhcpc/dhcpc.c index 724894bb9..3b0c2e191 100644 --- a/netutils/dhcpc/dhcpc.c +++ b/netutils/dhcpc/dhcpc.c @@ -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; }