diff options
author | Isaac Dunham <ibid.ag@gmail.com> | 2015-10-24 20:28:04 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-24 20:28:04 +0200 |
commit | d320a1e7a57512e351aa119beb2c18115f9c80ae (patch) | |
tree | af2a29b655a26ce6d804e90aced2abada084bc77 | |
parent | 334e12ac6a5c26a83e45e32436449730877de49a (diff) | |
download | busybox-w32-d320a1e7a57512e351aa119beb2c18115f9c80ae.tar.gz busybox-w32-d320a1e7a57512e351aa119beb2c18115f9c80ae.tar.bz2 busybox-w32-d320a1e7a57512e351aa119beb2c18115f9c80ae.zip |
dumpleases: new option -d to show time in seconds
function old new delta
dumpleases_main 493 534 +41
static.dumpleases_longopts 31 41 +10
packed_usage 30777 30752 -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 51/-25) Total: 26 bytes
Signed-off-by: Isaac Dunham <ibid.ag@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/udhcp/dumpleases.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c index 64cd73ec7..f68e499e7 100644 --- a/networking/udhcp/dumpleases.c +++ b/networking/udhcp/dumpleases.c | |||
@@ -4,18 +4,20 @@ | |||
4 | */ | 4 | */ |
5 | 5 | ||
6 | //usage:#define dumpleases_trivial_usage | 6 | //usage:#define dumpleases_trivial_usage |
7 | //usage: "[-r|-a] [-f LEASEFILE]" | 7 | //usage: "[-r|-a] [-d] [-f LEASEFILE]" |
8 | //usage:#define dumpleases_full_usage "\n\n" | 8 | //usage:#define dumpleases_full_usage "\n\n" |
9 | //usage: "Display DHCP leases granted by udhcpd\n" | 9 | //usage: "Display DHCP leases granted by udhcpd\n" |
10 | //usage: IF_LONG_OPTS( | 10 | //usage: IF_LONG_OPTS( |
11 | //usage: "\n -f,--file=FILE Lease file" | 11 | //usage: "\n -f,--file=FILE Lease file" |
12 | //usage: "\n -r,--remaining Show remaining time" | 12 | //usage: "\n -r,--remaining Show remaining time" |
13 | //usage: "\n -a,--absolute Show expiration time" | 13 | //usage: "\n -a,--absolute Show expiration time" |
14 | //usage: "\n -d,--decimal Show time in seconds" | ||
14 | //usage: ) | 15 | //usage: ) |
15 | //usage: IF_NOT_LONG_OPTS( | 16 | //usage: IF_NOT_LONG_OPTS( |
16 | //usage: "\n -f FILE Lease file" | 17 | //usage: "\n -f FILE Lease file" |
17 | //usage: "\n -r Show remaining time" | 18 | //usage: "\n -r Show remaining time" |
18 | //usage: "\n -a Show expiration time" | 19 | //usage: "\n -a Show expiration time" |
20 | //usage: "\n -d Show time in seconds" | ||
19 | //usage: ) | 21 | //usage: ) |
20 | 22 | ||
21 | #include "common.h" | 23 | #include "common.h" |
@@ -28,21 +30,22 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) | |||
28 | int fd; | 30 | int fd; |
29 | int i; | 31 | int i; |
30 | unsigned opt; | 32 | unsigned opt; |
31 | int64_t written_at, curr, expires_abs; | 33 | int64_t written_at, curr; |
32 | const char *file = LEASES_FILE; | 34 | const char *file = LEASES_FILE; |
33 | struct dyn_lease lease; | 35 | struct dyn_lease lease; |
34 | struct in_addr addr; | ||
35 | 36 | ||
36 | enum { | 37 | enum { |
37 | OPT_a = 0x1, // -a | 38 | OPT_a = 0x1, // -a |
38 | OPT_r = 0x2, // -r | 39 | OPT_r = 0x2, // -r |
39 | OPT_f = 0x4, // -f | 40 | OPT_f = 0x4, // -f |
41 | OPT_d = 0x8, // -d | ||
40 | }; | 42 | }; |
41 | #if ENABLE_LONG_OPTS | 43 | #if ENABLE_LONG_OPTS |
42 | static const char dumpleases_longopts[] ALIGN1 = | 44 | static const char dumpleases_longopts[] ALIGN1 = |
43 | "absolute\0" No_argument "a" | 45 | "absolute\0" No_argument "a" |
44 | "remaining\0" No_argument "r" | 46 | "remaining\0" No_argument "r" |
45 | "file\0" Required_argument "f" | 47 | "file\0" Required_argument "f" |
48 | "decimal\0" No_argument "d" | ||
46 | ; | 49 | ; |
47 | 50 | ||
48 | applet_long_options = dumpleases_longopts; | 51 | applet_long_options = dumpleases_longopts; |
@@ -50,11 +53,12 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) | |||
50 | init_unicode(); | 53 | init_unicode(); |
51 | 54 | ||
52 | opt_complementary = "=0:a--r:r--a"; | 55 | opt_complementary = "=0:a--r:r--a"; |
53 | opt = getopt32(argv, "arf:", &file); | 56 | opt = getopt32(argv, "arf:d", &file); |
54 | 57 | ||
55 | fd = xopen(file, O_RDONLY); | 58 | fd = xopen(file, O_RDONLY); |
56 | 59 | ||
57 | printf("Mac Address IP Address Host Name Expires %s\n", (opt & OPT_a) ? "at" : "in"); | 60 | printf("Mac Address IP Address Host Name Expires %s\n", |
61 | (opt & OPT_a) ? "at" : "in"); | ||
58 | /* "00:00:00:00:00:00 255.255.255.255 ABCDEFGHIJKLMNOPQRS Wed Jun 30 21:49:08 1993" */ | 62 | /* "00:00:00:00:00:00 255.255.255.255 ABCDEFGHIJKLMNOPQRS Wed Jun 30 21:49:08 1993" */ |
59 | /* "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 */ | 63 | /* "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 */ |
60 | 64 | ||
@@ -65,6 +69,9 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) | |||
65 | written_at = curr; /* lease file from future! :) */ | 69 | written_at = curr; /* lease file from future! :) */ |
66 | 70 | ||
67 | while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) { | 71 | while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) { |
72 | struct in_addr addr; | ||
73 | int64_t expires_abs; | ||
74 | |||
68 | const char *fmt = ":%02x" + 1; | 75 | const char *fmt = ":%02x" + 1; |
69 | for (i = 0; i < 6; i++) { | 76 | for (i = 0; i < 6; i++) { |
70 | printf(fmt, lease.lease_mac[i]); | 77 | printf(fmt, lease.lease_mac[i]); |
@@ -87,6 +94,13 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) | |||
87 | puts("expired"); | 94 | puts("expired"); |
88 | continue; | 95 | continue; |
89 | } | 96 | } |
97 | if (opt & OPT_d) { | ||
98 | /* -d: decimal time */ | ||
99 | if (!(opt & OPT_a)) | ||
100 | expires_abs -= curr; | ||
101 | printf("%llu\n", (unsigned long long) expires_abs); | ||
102 | continue; | ||
103 | } | ||
90 | if (!(opt & OPT_a)) { /* no -a */ | 104 | if (!(opt & OPT_a)) { /* no -a */ |
91 | unsigned d, h, m; | 105 | unsigned d, h, m; |
92 | unsigned expires = expires_abs - curr; | 106 | unsigned expires = expires_abs - curr; |