mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
DHCPv4: Updated LeaseTimeRemaining
This commit is contained in:
parent
09a3370be9
commit
196fa7098d
1 changed files with 25 additions and 0 deletions
|
|
@ -2446,6 +2446,14 @@ static int get_DHCPv4Client_DNSServers(char *refparam, struct dmctx *ctx, void *
|
|||
static int get_DHCPv4Client_LeaseTimeRemaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
struct uci_section *dhcpv4_s = ((struct dhcp_client_args *)data)->iface_s;
|
||||
FILE *fp = NULL;
|
||||
int lease_time;
|
||||
char *uptime_str;
|
||||
char *uptime = 0;
|
||||
int lease_uptime = 0;
|
||||
char *pch = NULL, *spch = NULL;
|
||||
char buf[16];
|
||||
int lease_remaining;
|
||||
|
||||
if (dhcpv4_s) {
|
||||
json_object *res = NULL;
|
||||
|
|
@ -2454,6 +2462,23 @@ static int get_DHCPv4Client_LeaseTimeRemaining(char *refparam, struct dmctx *ctx
|
|||
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", if_name, String}}, 1, &res);
|
||||
DM_ASSERT(res, *value = "0");
|
||||
*value = dmjson_get_value(res, 2, "data", "leasetime");
|
||||
lease_time = atoi(*value);
|
||||
if (lease_time == 0xFFFFFFFF) {
|
||||
*value = "-1";
|
||||
return 0;
|
||||
}
|
||||
fp = fopen("/proc/uptime", "r");
|
||||
if (fp != NULL) {
|
||||
if (fgets(buf, 16, fp) != NULL) {
|
||||
pch = strtok_r(buf, ".", &spch);
|
||||
uptime = (pch) ? dmstrdup(pch) : "0";
|
||||
uptime_str = dmjson_get_value(res, 2, "data", "uptime");
|
||||
lease_uptime = atoi(uptime_str);
|
||||
lease_remaining = lease_time - (atoi(uptime) - lease_uptime);
|
||||
sprintf(*value, "%d", lease_remaining);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue