diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-01-01 17:52:09 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-01-01 17:52:09 +0000 |
commit | 0416e3dde17ea9295635c52183b30fe3d7172333 (patch) | |
tree | 4eea1c401c74d6ec42f18c67090f73001103e0db /networking/udhcp/dumpleases.c | |
parent | b2ec03813c34bc3de2ddf9a0974be4e5b31ec757 (diff) | |
download | busybox-w32-0416e3dde17ea9295635c52183b30fe3d7172333.tar.gz busybox-w32-0416e3dde17ea9295635c52183b30fe3d7172333.tar.bz2 busybox-w32-0416e3dde17ea9295635c52183b30fe3d7172333.zip |
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 3e193903d..2d16ec160 100644 --- a/networking/udhcp/dumpleases.c +++ b/networking/udhcp/dumpleases.c | |||
@@ -12,7 +12,8 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) | |||
12 | int fd; | 12 | int fd; |
13 | int i; | 13 | int i; |
14 | unsigned opt; | 14 | unsigned opt; |
15 | time_t expires; | 15 | leasetime_t expires; |
16 | leasetime_t curr; | ||
16 | const char *file = LEASES_FILE; | 17 | const char *file = LEASES_FILE; |
17 | struct dhcpOfferedAddr lease; | 18 | struct dhcpOfferedAddr lease; |
18 | struct in_addr addr; | 19 | struct in_addr addr; |
@@ -38,27 +39,33 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) | |||
38 | 39 | ||
39 | printf("Mac Address IP-Address Expires %s\n", (opt & OPT_a) ? "at" : "in"); | 40 | printf("Mac Address IP-Address Expires %s\n", (opt & OPT_a) ? "at" : "in"); |
40 | /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */ | 41 | /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */ |
42 | |||
43 | curr = time(NULL); | ||
41 | while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) { | 44 | while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) { |
42 | printf(":%02x"+1, lease.chaddr[0]); | 45 | const char *fmt = ":%02x" + 1; |
43 | for (i = 1; i < 6; i++) { | 46 | for (i = 0; i < 6; i++) { |
44 | printf(":%02x", lease.chaddr[i]); | 47 | printf(fmt, lease.chaddr[i]); |
48 | fmt = ":%02x"; | ||
45 | } | 49 | } |
46 | addr.s_addr = lease.yiaddr; | 50 | addr.s_addr = lease.yiaddr; |
47 | printf(" %-15s ", inet_ntoa(addr)); | 51 | printf(" %-15s ", inet_ntoa(addr)); |
52 | if (lease.expires == 0) { | ||
53 | puts("expired"); | ||
54 | continue; | ||
55 | } | ||
48 | expires = ntohl(lease.expires); | 56 | expires = ntohl(lease.expires); |
49 | if (!(opt & OPT_a)) { /* no -a */ | 57 | if (!(opt & OPT_a)) { /* no -a */ |
50 | if (!expires) | 58 | unsigned d, h, m; |
51 | puts("expired"); | 59 | d = expires / (24*60*60); expires %= (24*60*60); |
52 | else { | 60 | h = expires / (60*60); expires %= (60*60); |
53 | unsigned d, h, m; | 61 | m = expires / 60; expires %= 60; |
54 | d = expires / (24*60*60); expires %= (24*60*60); | 62 | if (d) |
55 | h = expires / (60*60); expires %= (60*60); | 63 | printf("%u days ", d); |
56 | m = expires / 60; expires %= 60; | 64 | printf("%02u:%02u:%02u\n", h, m, (unsigned)expires); |
57 | if (d) printf("%u days ", d); | 65 | } else { /* -a */ |
58 | printf("%02u:%02u:%02u\n", h, m, (unsigned)expires); | 66 | time_t t = expires + curr; |
59 | } | 67 | fputs(ctime(&t), stdout); |
60 | } else /* -a */ | 68 | } |
61 | fputs(ctime(&expires), stdout); | ||
62 | } | 69 | } |
63 | /* close(fd); */ | 70 | /* close(fd); */ |
64 | 71 | ||