diff options
author | Denis Vlasenko | 2009-01-01 17:52:09 +0000 |
---|---|---|
committer | Denis Vlasenko | 2009-01-01 17:52:09 +0000 |
commit | 0416e3dde17ea9295635c52183b30fe3d7172333 (patch) | |
tree | 4eea1c401c74d6ec42f18c67090f73001103e0db /networking/udhcp/dumpleases.c | |
parent | b2ec03813c34bc3de2ddf9a0974be4e5b31ec757 (diff) | |
download | busybox-0416e3dde17ea9295635c52183b30fe3d7172333.zip busybox-0416e3dde17ea9295635c52183b30fe3d7172333.tar.gz |
udhcpd: disable opton to have absolute lease times in lease file
(that does not work with dumpleases)
dumpleases: fix -a option.
networking/udhcp/*: code shrink, more compact static leases struture,
better comments, etc
function old new delta
find_free_or_expired_address - 147 +147
nobody_responds_to_arp - 84 +84
read_opt 781 830 +49
dumpleases_main 435 447 +12
send_ACK 229 232 +3
read_staticlease 90 93 +3
addStaticLease 60 61 +1
getIpByMac 46 43 -3
reservedIp 31 20 -11
keywords 304 288 -16
send_offer 428 403 -25
write_leases 225 193 -32
read_leases 184 143 -41
read_yn 64 - -64
find_address 191 - -191
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 5/6 up/down: 299/-383) Total: -84 bytes
Diffstat (limited to 'networking/udhcp/dumpleases.c')
-rw-r--r-- | networking/udhcp/dumpleases.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c index 3e19390..2d16ec1 100644 --- a/networking/udhcp/dumpleases.c +++ b/networking/udhcp/dumpleases.c @@ -12,7 +12,8 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) int fd; int i; unsigned opt; - time_t expires; + leasetime_t expires; + leasetime_t curr; const char *file = LEASES_FILE; struct dhcpOfferedAddr lease; struct in_addr addr; @@ -38,27 +39,33 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) printf("Mac Address IP-Address Expires %s\n", (opt & OPT_a) ? "at" : "in"); /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */ + + curr = time(NULL); while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) { - printf(":%02x"+1, lease.chaddr[0]); - for (i = 1; i < 6; i++) { - printf(":%02x", lease.chaddr[i]); + const char *fmt = ":%02x" + 1; + for (i = 0; i < 6; i++) { + printf(fmt, lease.chaddr[i]); + fmt = ":%02x"; } addr.s_addr = lease.yiaddr; printf(" %-15s ", inet_ntoa(addr)); + if (lease.expires == 0) { + puts("expired"); + continue; + } expires = ntohl(lease.expires); if (!(opt & OPT_a)) { /* no -a */ - if (!expires) - puts("expired"); - else { - unsigned d, h, m; - d = expires / (24*60*60); expires %= (24*60*60); - h = expires / (60*60); expires %= (60*60); - m = expires / 60; expires %= 60; - if (d) printf("%u days ", d); - printf("%02u:%02u:%02u\n", h, m, (unsigned)expires); - } - } else /* -a */ - fputs(ctime(&expires), stdout); + unsigned d, h, m; + d = expires / (24*60*60); expires %= (24*60*60); + h = expires / (60*60); expires %= (60*60); + m = expires / 60; expires %= 60; + if (d) + printf("%u days ", d); + printf("%02u:%02u:%02u\n", h, m, (unsigned)expires); + } else { /* -a */ + time_t t = expires + curr; + fputs(ctime(&t), stdout); + } } /* close(fd); */ |