Skip to content
Snippets Groups Projects
Commit 07b1cae4 authored by Anjan Chanda's avatar Anjan Chanda
Browse files

fix print format for dhcp lease-time remaining

parent 9d3585bd
Branches
No related tags found
No related merge requests found
...@@ -222,20 +222,19 @@ int read_dhcpv4_lease_table(void **clients, int *num_clients) ...@@ -222,20 +222,19 @@ int read_dhcpv4_lease_table(void **clients, int *num_clients)
int cnt = 0; int cnt = 0;
int ret = 0; int ret = 0;
fprintf(stderr, "%s: %d -------->\n", __func__, __LINE__);
f = fopen("/var/dhcp.leases", "r"); f = fopen("/var/dhcp.leases", "r");
if (!f) if (!f)
return -1; return -1;
while (fgets(line, sizeof(line), f) != NULL) { while (fgets(line, sizeof(line), f) != NULL) {
long leasetime; unsigned long leasetime = 0;
char macaddr[18] = {0}; char macaddr[18] = {0};
char ipaddr[24] = {0}; char ipaddr[24] = {0};
char hostname[256] = {0}; char hostname[256] = {0};
char clid[256] = {0}; char clid[256] = {0};
remove_newline(line); remove_newline(line);
if (sscanf(line, "%ld %17s %23s %255s %255s", &leasetime, if (sscanf(line, "%lu %17s %23s %255s %255s", &leasetime,
macaddr, ipaddr, hostname, clid) == 5) { macaddr, ipaddr, hostname, clid) == 5) {
hosts = realloc(hosts, (cnt + 1) * sizeof(struct dhcp_clients)); hosts = realloc(hosts, (cnt + 1) * sizeof(struct dhcp_clients));
...@@ -248,7 +247,6 @@ int read_dhcpv4_lease_table(void **clients, int *num_clients) ...@@ -248,7 +247,6 @@ int read_dhcpv4_lease_table(void **clients, int *num_clients)
tmp = hosts + cnt; tmp = hosts + cnt;
memset(tmp, 0, sizeof(struct dhcp_clients)); memset(tmp, 0, sizeof(struct dhcp_clients));
hwaddr_aton(macaddr, tmp->macaddr); hwaddr_aton(macaddr, tmp->macaddr);
fprintf(stderr, "%s: host " MACFMT "\n", __func__, MAC2STR(tmp->macaddr));
strncpy(tmp->ipv4, ipaddr, sizeof(ipaddr)-1); strncpy(tmp->ipv4, ipaddr, sizeof(ipaddr)-1);
strncpy(tmp->hostname, hostname, sizeof(hostname)-1); strncpy(tmp->hostname, hostname, sizeof(hostname)-1);
tmp->leasetime = leasetime; tmp->leasetime = leasetime;
......
...@@ -252,8 +252,6 @@ int topologyd_ubus_status(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -252,8 +252,6 @@ int topologyd_ubus_status(struct ubus_context *ctx, struct ubus_object *obj,
{ {
int ret = 0; int ret = 0;
//ret = topology_get_status(p); // TODO
return ret; return ret;
} }
...@@ -379,7 +377,7 @@ int topologyd_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -379,7 +377,7 @@ int topologyd_ubus_show_hosts(struct ubus_context *ctx, struct ubus_object *obj,
blobmsg_add_string(&bb, "ipv4addr", ip4buf); blobmsg_add_string(&bb, "ipv4addr", ip4buf);
leasetime_rem = e->leasetime ? e->leasetime - (unsigned long)time(NULL) : 0; leasetime_rem = e->leasetime ? e->leasetime - (unsigned long)time(NULL) : 0;
blobmsg_add_string(&bb, "address_source", leasetime_rem ? "DHCP": "Static"); blobmsg_add_string(&bb, "address_source", leasetime_rem ? "DHCP": "Static");
blobmsg_add_u64(&bb, "lease_time_remaining", leasetime_rem); blobmsg_add_u32(&bb, "lease_time_remaining", leasetime_rem);
blobmsg_add_u8(&bb, "iswifi", e->type == NEIGH_TYPE_WIFI ? true : false); blobmsg_add_u8(&bb, "iswifi", e->type == NEIGH_TYPE_WIFI ? true : false);
blobmsg_add_u8(&bb, "is1905", e->is1905 ? true : false); blobmsg_add_u8(&bb, "is1905", e->is1905 ? true : false);
rtnl_neigh_state2str(e->state, statestr, sizeof(statestr)); rtnl_neigh_state2str(e->state, statestr, sizeof(statestr));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment